Home » Developer & Programmer » JDeveloper, Java & XML » Connect to ORACLE via JDBC
Connect to ORACLE via JDBC [message #366709] Tue, 24 October 2000 14:13 Go to next message
Leon LI
Messages: 1
Registered: October 2000
Junior Member
Hi,

I got a problem when trying to use JDBC driver. I downloaded
JDBC driver from Oracle site. The codes was compiled successfully,
but got error message when I executed them.

I need your help for the solution.

Thanks,

Leon,

Here is my source codes:

====================================================================================
for JDBC Thin:

import java.sql.*;
import java.math.*;
import java.io.*;

class dbAccessThin {
public static void main (String args [[]]) throws SQLException
{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());

Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@venus:1526:db15", "scott", "tiger");
// @machineName:port:SID, userid, password

Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select sysdate from dual");
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
stmt.close();
}
}

Error message are:

java.sql.SQLException: The Network Adapter could not establish the connection
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java)
at java.sql.DriverManager.getConnection(Compiled Code)
at java.sql.DriverManager.getConnection(DriverManager.java:126)
at dbAccessThin.main(Compiled Code)

=========================================================================
For JDBC OCI8:

import java.sql.*;
import java.math.*;
import java.lang.*;
import oracle.jdbc.*;

class dbAccessOCI {
public static void main (String args [[]]) throws SQLException
{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());

Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@db15", "scott", "tiger");
// or oci7 @TNSNames_Entry, userid, password

Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select sysdate from dual");
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
stmt.close();
}
}

java.lang.UnsatisfiedLinkError: no ocijdbc8 in shared library path
at java.lang.Runtime.loadLibrary(Compiled Code)
at java.lang.System.loadLibrary(System.java:561)
at oracle.jdbc.oci8.OCIDBAccess.logon(OCIDBAccess.java)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java)
at java.sql.DriverManager.getConnection(Compiled Code)
at java.sql.DriverManager.getConnection(DriverManager.java:126)
at dbAccessOCI.main(Compiled Code)
Re: Connect to ORACLE via JDBC [message #366710 is a reply to message #366709] Tue, 24 October 2000 14:23 Go to previous messageGo to next message
Radhesh Mohandas
Messages: 20
Registered: August 2000
Junior Member
Hi,

1> Make sure that you have changed the connection
string to your host in case u are modifing a sample code

2> I guess the listener is not up. u have to start
it on the database server. try tnsping venus to check

3> Put the LD_LIBRARY_PATH proper - That is why
your oci8 driver is not working.
Re: Connect to ORACLE via JDBC [message #366712 is a reply to message #366709] Tue, 24 October 2000 17:12 Go to previous message
Radhesh Mohandas
Messages: 20
Registered: August 2000
Junior Member
Hi Radhesh,

Thanks for your response.

I verified that database is up, and listener was running
on our server. The string name is correct, since I can
connect to database via SQL*Plus using the same string
name.

What does LD_LIBRARY_PATH mean? Should I add
this to system variable PATH?

Thanks,

Leon,

Hi,

1> The default port is 1521 - u may be looking at
the wrong port
2> LD_LIBRARY_PATH is an environment variable which helps the .so library required for oci8 driver. add $ORA_HOM/lib and $ORA_HOM/jdbc/lib to it.

3> Try the thin driver with localhost first.

4> There are 3 ways to specify the connect string:

// get a default connection
/* Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger");

// Using tnsnames.ora
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@db.yourhost", "scott", "tiger");

// Using Net 8 keyword value pairs -
// Tries first IPC protocol and on failure tries TCP
String connectString =
"(DESCRIPTION = "+
"(ADDRESS_LIST = " +
"(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))"+
"(ADDRESS = (PROTOCOL = TCP)(HOST = yourhost)(PORT = 1521))"+
")"+
"(CONNECT_DATA = "+
" (SERVICE_NAME = yourhost) "+
")"+
")";
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@"+connectString,
"scott", "tiger");

5> For more information read jdbc developers guide from oracle

-Radhesh
Previous Topic: Help!about the installation of JDK
Next Topic: Help!about JDeveloper
Goto Forum:
  


Current Time: Tue Aug 03 22:33:31 CDT 2021