• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting oracle without creating DSN

 
amar nath jha
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
amar nath jha
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic