Hi..I am trying to connect oracle which is on my pc.i am using oracle 9i.
i am creating 1 customer table & trying to display it.
import java.sql.*;
import java.net.*;
public class JdbcDemo{
public static void main(String args[]){
Driver d;
Connection con;
Statement stmt ;
ResultSet rs;
try{
d=(Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
System.out.println("Got driver");
con =DriverManager.getConnection("jdbc:odbc:thin:@localhost:1521:XE","scott","tiger");
// con =DriverManager.getConnection("jdbc:oracle:thin:2030:oracle","scott","tiger");
System.out.println("Got Connection");
stmt = con.createStatement();
System.out.println("Statement object created");
rs= stmt.executeQuery("select * from customer");
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(1)+" "+rs.getString(2));
}
}
catch(IllegalAccessException e){
System.out.println("in IllegalAccess exception");
e.printStackTrace( System.out );
}
catch(ClassNotFoundException e){
System.out.println("in class not Found exception");
e.printStackTrace( System.out );
}
catch(SQLException e){
System.out.println("in SQLException exception");
e.printStackTrace( System.out );
}
catch(Exception e){
System.out.println("in exception");
e.printStackTrace( System.out );
}
}
}
It gives Error.....
Got driver
in SQLException exception
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not fou
nd and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:3
23)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Jdbc2.main(Jdbc2.java:13)