• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

oracle and jdbc-odbc bridge

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I am facing a problem in connecting this simple program
to the oracle8 database.
I am trying
to connect to the oracle database (which is residing
on my local machine as of now) through a JDBC-ODBC
bridge, and then execute the "emp" table of the "scott" user
---> what i am still not familiar is how to pass the connection string in
the ODBC data source administrator dialog box?
--> what kind of entry i should make
in TNSnames.ora file, to connect to the local database where the "emp"
table is situated?
--> how do i know the host and Port no for the database on which the
"emp" table resides?
<code>

import java.io.*;
import java.sql.*;
public class CreateCoffees1 {
public static void main(String args[]) throws IOException {
String url = "jdbc:odbc:testing";
Connection con;
Statement stmt;

try {
/*we are creating a connection to the database using the JDBC-Bridge Driver*/
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url,"scott","tiger");
stmt = con.createStatement();
ResultSet srs = stmt.executeQuery("SELECT * FROM emp");
while (srs.next()) {
String name = srs.getString("ENAME");
String job = srs.getString("JOB");
System.out.println(name + " " + job);
}

stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException hai bhai: " + ex.getMessage());
}
}
}
</code>

thanks in advance.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello!friend
if it is for localhost there is no need to make in entries in tnsnames.ora file.
simply creating dsn is enough.
goto control panel-click odbc32..icon-in the dialog press add-
select the oracledriver-enter dsn...etc..you will find it very easy.
i hope this is what you wanted
 
reply
    Bookmark Topic Watch Topic
  • New Topic