• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connecting oracle without creating DSN

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 = "jdbc:odbc:DRIVER={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="jdbc:odbc:DRIVER={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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic