• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help connecting to Access DB

 
Josh Forrest
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what i have...
Connection conn = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc.odbc:josh");
System.out.println("connection = " + conn);
---------------------------
conn comes back null, i'm not sure if this part of my code is correct...
("jdbc.odbc:josh");
where josh is the name of my Access database.
thanks for any help!
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to set up a DSN if you want to use the ODBC driver.
[ January 23, 2003: Message edited by: Thomas Paul ]
 
Josh Forrest
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the DSN set up, i'm concerned that this part of my code is incorrect...
conn = DriverManager.getConnection("jdbc.odbc:josh");
i'm not sure if i should use the DB name(josh) here, or if i should insert something else there?
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Josh,
the syntax is DriverManager.getConnection("jdbcdbcBName","user","password");
Where DBName is your database name, not the table name. If you didn't set a user and a password, try with empty quotes (just a guess). And check that your DSN is correctly set.
Hope it helps
[edited to remove the smilies]
[ January 23, 2003: Message edited by: Younes Essouabni ]
 
Sam Moran
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh, I gave you the code in the other thread it is as follows:

It is important that the DSN entry must have the same case as the url assignment. So, here it would be Josh. My suggestion would be to use all upper or all lower case. The DSN entry contains all of the information about you DB, where it is and its name. The connection that you create in your Java program is connecting to the DSN entry that has the location and name information. If you want to see if the connection was successful try this:

[ January 24, 2003: Message edited by: Sam Moran ]
[ January 24, 2003: Message edited by: Sam Moran ]
[ January 24, 2003: Message edited by: Sam Moran ]
[ January 24, 2003: Message edited by: Sam Moran ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic