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.