|
-
java jdbc connection on w2k, Oracle8i, JDK1.3
Would like one simple thing:
Connect to oracle8i with jdbc on Win2k.
Offering $25 email thank you gift/s to person/s who help
solve/s this mystery. Don't care which driver or how
(as long as it's downloadable & free).
FACTS & ASSUMPTIONS:
- localhost copy of Oracle 8i for NT, running fine.
- Other uses of jdk1.3 environ seems to be working fine to
compile & run java programs(which don't yet use jdbc).
- Downloaded latest jdbc classes( 3.0 ) from Sun &
placed in classpath. File name = jdbc-3_0-pfd2-classes.zip
= 34,313 bytes from: http://java.sun.com/Download4.
* assuming: jdbc driver is a part of above zip file. *
---------------------------------------------------------------
Have simple java test program which attempts nothing
more than make a measly connection. No luck. Here
is output:
"class found" <-- message printed by running program
"now try connection..." <-- my debug message printed by program
***SQLException caught*** <- this error hits at "Connection con =.."
------------------------------------------------------------------
Error message is:
SQLState: IM002
Message: [Microsoft][ODBC Driver Manager] Data source name not found and
no default driver specified
Vendor: 0
-------------------------------------------------------------
Given the above driver is a jdbc dbc bridge driver, I suspected odbc
installation may be the culprit. Not so. ODBC is functional
and connects nicely using "odbctst.exe" tool which Oracle
provides to test ODBC.
Willing to scrap use of javasoft driver & attempt oracle
driver at following location. Would prefer to know why
this example is not working before trying other drivers
(if possible).
Here is driver location & URL I'll be trying next
in the event I cant get sun driver to work. Any
pointers on this new install to help avoid similar snags
would be welcome.
http://otn.oracle.com/software/tech/...ware_index.htm
Oracle8i 8.1.7 JDBC Drivers for use with JDK 1.2.x
Download the drivers and readme
Readme before downloading the driver zip files.
JDBC-Thin, 100% Java ( 1.9MB)
JDBC-OCI / NT (1,905 kb) Note: Oracle 8.1.7 Client must be
installed before the OCI driver can be used.
----------------------------------------------------------
Here is test java test code ( which is failing @ execute time:
-----------------------------------------------------------
C:\Documents and Settings\Administrator\Desktop\jdbctest>type simpleselect.java
//----------------------------------------------------------------------------
//
// Module: simpleselect.java
//
// Description: Test program for ODBC API interface. This java application
// will connection to a JDBC driver, issue a select statement
// and display all result columns and rows
//
// Product: JDBC to ODBC Bridge
//
// Author: Karl Moss
//
// Date: February, 1996
//
// Copyright: 1990-1996 INTERSOLV, Inc.
// This software contains confidential and proprietary
// information of INTERSOLV, Inc.
//----------------------------------------------------------------------------
import java.net.URL;
import java.sql.*;
class simpleselect {
public static void main (String args[]) {
//String url = "jdbc dbc:my-dsn";
String url = "jdbc dbc://forrest.dnax.org/OracleODBCDriverDSN";
String query = "SELECT count(*) FROM scott.emp";
// String query = "SELECT count(*) FROM Cases";
try {
// Load the jdbc-odbc bridge driver
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
// Attempt to connect to a driver. Each one
// of the registered drivers will be loaded until
// one is found that can process this URL
System.err.println("class found");
System.err.println("now try connection con... ");
// url, "my-user", "my-passwd");
Connection con = DriverManager.getConnection ( url, "system", "manager");
System.err.println("after connection");
// If we were unable to connect, an exception
// would have been thrown. So, if we get here,
// we are successfully connected to the URL
// Check for, and display and warnings generated
// by the connect.
checkForWarning (con.getWarnings ());
// Get the DatabaseMetaData object and display
// some information about the connection
DatabaseMetaData dma = con.getMetaData ();
System.out.println("\nConnected to " + dma.getURL());
System.out.println("Driver " +
dma.getDriverName());
System.out.println("Version " +
dma.getDriverVersion());
System.out.println("");
// Create a Statement object so we can submit
// SQL statements to the driver
Statement stmt = con.createStatement ();
// Submit a query, creating a ResultSet object
ResultSet rs = stmt.executeQuery (query);
// Display all columns and rows from the result set
dispResultSet (rs);
// Close the result set
rs.close();
// Close the statement
stmt.close();
// Close the connection
con.close();
}
catch (SQLException ex) {
// A SQLException was generated. Catch it and
// display the error information. Note that there
// could be multiple error objects chained
// together
System.out.println ("\n*** SQLException caught ***\n");
while (ex != null) {
System.out.println ("SQLState: " +
ex.getSQLState ());
System.out.println ("Message: " +
ex.getMessage ());
System.out.println ("Vendor: " +
ex.getErrorCode ());
ex = ex.getNextException ();
System.out.println ("");
}
}
catch (java.lang.Exception ex) {
// Got some other type of exception. Dump it.
ex.printStackTrace ();
}
}
//-------------------------------------------------------------------
// checkForWarning
// Checks for and displays warnings. Returns true if a warning
// existed
//-------------------------------------------------------------------
private static boolean checkForWarning (SQLWarning warn)
throws SQLException
{
boolean rc = false;
// If a SQLWarning object was given, display the
// warning messages. Note that there could be
// multiple warnings chained together
if (warn != null) {
System.out.println ("\n *** Warning ***\n");
rc = true;
while (warn != null) {
System.out.println ("SQLState: " +
warn.getSQLState ());
System.out.println ("Message: " +
warn.getMessage ());
System.out.println ("Vendor: " +
warn.getErrorCode ());
System.out.println ("");
warn = warn.getNextWarning ();
}
}
return rc;
}
//-------------------------------------------------------------------
// dispResultSet
// Displays all columns and rows in the given result set
//-------------------------------------------------------------------
private static void dispResultSet (ResultSet rs)
throws SQLException
{
int i;
// Get the ResultSetMetaData. This will be used for
// the column headings
ResultSetMetaData rsmd = rs.getMetaData ();
// Get the number of columns in the result set
int numCols = rsmd.getColumnCount ();
// Display column headings
for (i=1; i<=numCols; i++) {
if (i > 1) System.out.print(",");
System.out.print(rsmd.getColumnLabel(i));
}
System.out.println("");
// Display data, fetching until end of the result set
while (rs.next ()) {
// Loop through each column, getting the
// column data and displaying
for (i=1; i<=numCols; i++) {
if (i > 1) System.out.print(",");
System.out.print(rs.getString(i));
}
System.out.println("");
// Fetch the next result set row
}
}
}
-------------------------------------------------------------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks