Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: jdbc connection

Re: jdbc connection

From: Rauf Sarwar <rs_arwar_at_hotmail.com>
Date: 5 May 2006 09:58:23 -0700
Message-ID: <1146848303.861913.161640@g10g2000cwb.googlegroups.com>

tejasvi.patil_at_gmail.com wrote:
> 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
> ("jdbc:oracle: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/software/tech/java/sqlj_jdbc/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("jdbc:oracle:thin:@host:port:sid", p);

Regards
/Rauf Received on Fri May 05 2006 - 11:58:23 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US