*
The moose likes JDBC and the fly likes Connecting oracle without creating DSN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connecting oracle without creating DSN" Watch "Connecting oracle without creating DSN" New topic
Author

Connecting oracle without creating DSN

amar nath jha
Ranch Hand

Joined: Mar 09, 2006
Posts: 42
This code is working fine with SQL server.
But when I tried to make changes to make it work for Oracle its giving me error.
Please help.


// Step 1: Load the JDBC driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//String url = "jdbcdbcRIVER={SQL Server};Server=saraswati;Database=master;"; //for sql server

// Step 2: Establish the connection to the database.
//Connection conn = DriverManager.getConnection(url,"sa","sa"); //for sqlserver



String url="jdbcdbcRIVER={Oracle in OraHome90};Server=saraswati;Database=stud1";//for Oracle9
Connection conn = DriverManager.getConnection(url,"scott","tiger");//for Oracle9
if(conn instanceof Connection)
{
System.out.println("DONE");
Statement s=conn.createStatement();
// ResultSet rs=s.executeQuery("select areaname from AreaMaster order by areaName");
ResultSet rs = s.executeQuery("select * from stud1");
while(rs.next())
{
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));

}
}
else
{
System.out.println("NOT DONE");
}

}
catch (Exception e)
{
System.err.println("Got an exception! " + e.toString());

}



Its giving me TSN:protocol adapter error.
DRIVER name is Oracle in OraHome90
Server name is saraswati
Table name stud1
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Why are you using the JDBC-ODBC bridge to connect (see the first two lines of this )? Use the thin driver instead and you don't need a DSN. Read the "JDBC Developer's Guide and Reference" in your Oracle documentation for fairly comprehensive documentation and examples.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
amar nath jha
Ranch Hand

Joined: Mar 09, 2006
Posts: 42
ya its fine but please see the comments for SQL Server the code works if we remove comments and put comment before lines for oracle9.
can't it be same for oracle
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Again, why are you using the JDBC-ODBC bridge with SQL Server? Use a proper type 4 driver and you don't need a DSN. Microsoft provide their own (see msdn), or you can download jTDS (google for it).
amar nath jha
Ranch Hand

Joined: Mar 09, 2006
Posts: 42
Thanks
 
jQuery in Action, 2nd edition
 
subject: Connecting oracle without creating DSN
 
Similar Threads
how to create summary and detail table
questions in jdbc
No suitable driver using msql
no dafault driver specified
Passing ResultSet to JSP