This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes JDBC and the fly likes need help connecting to Access DB Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "need help connecting to Access DB" Watch "need help connecting to Access DB" New topic
Author

need help connecting to Access DB

Josh Forrest
Greenhorn

Joined: Oct 08, 2002
Posts: 7
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

Joined: May 05, 2000
Posts: 13974
You have to set up a DSN if you want to use the ODBC driver.
[ January 23, 2003: Message edited by: Thomas Paul ]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Josh Forrest
Greenhorn

Joined: Oct 08, 2002
Posts: 7
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

Joined: Jan 13, 2002
Posts: 479
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 ]

Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Sam Moran
Ranch Hand

Joined: Sep 28, 2002
Posts: 86
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 ]

We make a living by what we get, we make a life by what we give!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: need help connecting to Access DB
 
Similar Threads
Accessing Connection pool
close sql connection in finally block
Getting Error Oracle.jdbc.driver does not exist
how does this declaration differs !!!
Connection object