I am using ms access 97 database and I want to read data from it (Oscar1.mdb) and display it on the command prompt. Here is my code. import java.sql.*; import java.util.*; public class myJdbc{ public static void main(String args[]){ String url="jdbc dbc scar1"; String query= "SELECT * FROM Person"; Statement stmt; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); }catch (ClassNotFoundException e) { System.out.println(e+" The class is not found"); }
try{ Connection con =DriverManager.getConnection(url); stmt= con.createStatement(); ResultSet rs = stmt.executeQuery(query);
} rs.close(); stmt.close(); con.close(); }catch(SQLException ex ){ ex.printStackTrace(); } } } After compiling and running the code I'm geting these errors. java.sql.SQLExeception: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified at sun.jdbc.JdbcOdbc.createSQLExeception(JdbcOdbc.java:6106) at sun.jdbc.JdbcOdbc.standardError(JdbcOdbc.java:6263) at sun.jdbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:2488) at sun.jdbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:317)
at sun.jdbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:160) at java.sql.DriverManager.getConnection(DriverManager.java:171) at myJdbc.main(myJdbc.java:21) I am a beginner java and anxious to move on. Please help...
Chris Mathews
Ranch Hand
Joined: Jul 18, 2001
Posts: 2712
posted
0
Did you create a DSN named Oscar1? If not then that is your next step. You can also connect without using a DSN, the syntax is similar to this:
Oscar Kamau
Greenhorn
Joined: Oct 02, 2002
Posts: 20
posted
0
Originally posted by Chris Mathews: Did you create a DSN named Oscar1? If not then that is your next step. You can also connect without using a DSN, the syntax is similar to this:
Thanks Chris. I opted to connect without using the DSN, but unfotunately, I'm getting the same errors. Oscar
Oscar Kamau
Greenhorn
Joined: Oct 02, 2002
Posts: 20
posted
0
Thanks very much Chris Mathews. Your code worked finally. The reason it had earlier failed is due to the naming of the Access 97 drivers on the computer I was using. Thanks a lot, I appreciate it.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.