dbTalk Databases Forums  

jdbc connection

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss jdbc connection in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default jdbc connection - 05-05-2006 , 05:50 AM






Hello,
I have installed java 2 SDK 1.4 on my windows XP machine.
I want to connect to oracle database server (machine name - myserver)
where Oracle 9i is installed.
I am running following java code....

import java.sql.*;
import sun.jdbc.odbc.*;
class dba {
public static void main (String args []) throws SQLException
{
try {
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");

System.out.println("driver is loaded dynamically");
//Class.forName ("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

Connection conn = DriverManager.getConnection
("jdbcracle:thin:@myserver:1521:sdms60", "sys","password");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select * from
NGSDMS60.NGTAGS");
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
stmt.close();
}
}
But it gives runtime error as follows:
driver is loaded dynamically
Exception in thread "main" java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager .java:532)
at java.sql.DriverManager.getConnection(DriverManager .java:171)
at dba.main(dba.java:15)

Can anyone please help in this???
Do i need to insatll or need to do some settings through control panel
on server / client machine??

Thanks in advance!!!

regards,
Tejasvi Patil


Reply With Quote
  #2  
Old   
Thomas Kellerer
 
Posts: n/a

Default Re: jdbc connection - 05-05-2006 , 06:15 AM






On 05.05.2006 12:50 tejasvi.patil (AT) gmail (DOT) com wrote:
Quote:
Hello,
I have installed java 2 SDK 1.4 on my windows XP machine.
I want to connect to oracle database server (machine name - myserver)
where Oracle 9i is installed.
I am running following java code....

[...]
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
This is the wrong classname you need oracle.jdbc.OracleDriver

Thomas


Reply With Quote
  #3  
Old   
Rauf Sarwar
 
Posts: n/a

Default Re: jdbc connection - 05-05-2006 , 11:58 AM




tejasvi.patil (AT) gmail (DOT) com wrote:
Quote:
Hello,
I have installed java 2 SDK 1.4 on my windows XP machine.
I want to connect to oracle database server (machine name - myserver)
where Oracle 9i is installed.
I am running following java code....

import java.sql.*;
import sun.jdbc.odbc.*;
class dba {
public static void main (String args []) throws SQLException
{
try {
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");

System.out.println("driver is loaded dynamically");
//Class.forName ("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

Connection conn = DriverManager.getConnection
("jdbcracle:thin:@myserver:1521:sdms60", "sys","password");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select * from
NGSDMS60.NGTAGS");
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
stmt.close();
}
}
But it gives runtime error as follows:
driver is loaded dynamically
Exception in thread "main" java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager .java:532)
at java.sql.DriverManager.getConnection(DriverManager .java:171)
at dba.main(dba.java:15)

Can anyone please help in this???
Do i need to insatll or need to do some settings through control panel
on server / client machine??

Thanks in advance!!!

regards,
Tejasvi Patil
You are using the wrong driver as already pointed out. Follow these
guidelines,

1) If you want to make an "thick" connection using native Oracle
libraries then you would need to install Oracle client.

2) If you want to make a "thin" connection (Which you are attempting to
do) then you would need the Oracle jdbc driver only. For Oracle 9i and
depending on your java version, it's ojdbc14.jar or classes12.zip,
which you can download from
http://www.oracle.com/technology/sof...dbc/index.html.
You would need to put the jar/zip file in your classpath and use
Class.forName ("oracle.jdbc.OracleDriver");

3) You are attempting a SYS connection to the database. If your
database allows remote SYS connections then the connection string must
include "as sysdba". To do this in java you would pass the connection
string as Properties e.g.

Properties p = new Properties();
p.put("user", "value");
p.put("password", "value");
p.put("internal_logon", "sysdba");
Connection c =
DriverManager.getConnection("jdbcracle:thin:@hos tort:sid", p);

Regards
/Rauf



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.