Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

oracle8i NT jdbc connection jdk1.3

Status
Not open for further replies.
Would like one simple thing:

*** Connect to Oracle8i with jdbc on NT!! ****

Don't care which driver or how (as long as it's & 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 programs(which don't yet incorporate jdbc).

- Downloaded latest jdbc classes( 3.0 ) from Sun &
placed in classpath. File name = jdbc-3_0-pfd2-classes.zip = 34,313 bytes from:
* 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:

&quot;class found&quot; <-- message printed by running program
&quot;now try connection...&quot; <-- my debug message printed by program

***SQLException caught*** <- this error hits at &quot;Connection con =..&quot;
------------------------------------------------------------------
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:eek:dbc bridge driver, I suspected odbc
installation may be the culprit. Not so. ODBC is functional and connects
nicely using &quot;odbctst.exe&quot; 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.

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:
-----------------------------------------------------------
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 = &quot;jdbc:eek:dbc:my-dsn&quot;;

String url = &quot;jdbc:eek:dbc://hostname.company.org/OracleODBCDriverDSN&quot;;

String query = &quot;SELECT count(*) FROM scott.emp&quot;;
// String query = &quot;SELECT count(*) FROM Cases&quot;;

try {

// Load the jdbc-odbc bridge driver

Class.forName (&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;);

// 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(&quot;class found&quot;);

System.err.println(&quot;now try connection con... &quot;);

// url, &quot;my-user&quot;, &quot;my-passwd&quot;);
Connection con = DriverManager.getConnection ( url, &quot;system&quot;, &quot;manager&quot;);

System.err.println(&quot;after connection&quot;);

// 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(&quot;\nConnected to &quot; + dma.getURL());
System.out.println(&quot;Driver &quot; +
dma.getDriverName());
System.out.println(&quot;Version &quot; +
dma.getDriverVersion());
System.out.println(&quot;&quot;);

// 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 (&quot;\n*** SQLException caught ***\n&quot;);

while (ex != null) {
System.out.println (&quot;SQLState: &quot; +
ex.getSQLState ());
System.out.println (&quot;Message: &quot; +
ex.getMessage ());
System.out.println (&quot;Vendor: &quot; +
ex.getErrorCode ());
ex = ex.getNextException ();
System.out.println (&quot;&quot;);
}
}
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 (&quot;\n *** Warning ***\n&quot;);
rc = true;
while (warn != null) {
System.out.println (&quot;SQLState: &quot; +
warn.getSQLState ());
System.out.println (&quot;Message: &quot; +
warn.getMessage ());
System.out.println (&quot;Vendor: &quot; +
warn.getErrorCode ());
System.out.println (&quot;&quot;);
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(&quot;,&quot;);
System.out.print(rsmd.getColumnLabel(i));
}
System.out.println(&quot;&quot;);

// 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(&quot;,&quot;);
System.out.print(rs.getString(i));
}
System.out.println(&quot;&quot;);

// Fetch the next result set row

}
}
}
------------------------------------------------------------
 
Looking at your code quickly it seems okay with the exception of your URL. I normally see the port number and the connection information to the db but only saw a String which was the name of your DSN connection I would assume. JDBC and ODBC are two different types of drivers and require different connections schemas.

I currently use the oracle Drivers on NT and do not have any problems when I change the URL to an actual database running the samples provided by oracle scott/tiger.

 
Sorry to be of no use, but I've been trying to get the Oracle JDBC driver working myself. If you get it working can you post how you did it? I'm trying to get Tomcat to recognize the drivers, but so far to no avail. I've tried everything I've read but nothing works. My programs run fine in JDeveloper and can connect to the database from there, but once I move my programs over to the server I get the error JDBC drivers not found. I know that my classpath is set correctly. Is there any expert on setting up JDBC drivers for Oracle in Tomcat or some other web server that can post the steps. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top