Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

jdbc connect Access

 
Ranch Hand
Posts: 235
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I am new to JDBC. I tried to connect to MS Access, but always give the following error:
C:\>java JdbcTest1
Error Creating Record
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JdbcTest1.doTest(JdbcTest1.java:8)
at JdbcTest1.main(JdbcTest1.java:29)
I try to look through all the threads, but unable to solve it.
Please help. I use jdk 1.3 . I did go to settings->control panel to create a DSN.
Here is the program (taken from this forum)
<CODE>
import java.sql.*;
public class JdbcTest1 {
public void doTest(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc odbc:Records","","") ;
Statement stmt = con.createStatement();
System.out.println("Table Created?"+stmt.executeUpdate("create table mytable (sno integer, name varchar(20) )"));
System.out.println("Inserted?"+stmt.executeUpdate("insert into mytable values (1, 'Silly')"));
System.out.println("Inserted?"+stmt.executeUpdate ("insert into mytable values (2, 'Ken')"));
ResultSet rs = stmt.executeQuery("select * from mytable");
while ( rs.next() ){
System.out.println("SNO ==>"+rs.getInt("sno")+"\n");
System.out.println("SNO ==>"+rs.getString("name")+"\n");
}
}catch (Exception e){
System.out.println("Error Creating Record");
e.printStackTrace();
}
}
public static void main( String[] args ) {
JdbcTest1 test = new JdbcTest1();
test.doTest();
}
}
</CODE>
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simon,
It looks like you have a space (" ") instead of a colon (":") between "jdbc" and "odbc" in your URL. In other words, it should be:
jdbc:odbc:Records
instead of:
jdbc odbc:Records
The error message you received indicates that no registered driver understands the URL you specified, which in this case is because the URL is incorrect.
------------------
Brett Spell
Author, Professional Java Programming
[This message has been edited by Brett Spell (edited March 21, 2001).]
 
Simon Xu
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, Brett,
After changing the space, it works now. Thanks
Simon
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic