File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Connecting to an existing db Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Connecting to an existing db" Watch "Connecting to an existing db" New topic

Connecting to an existing db

Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
I've created a MySQL database on my local workstation. Made a table and added some info and so forth. Now my question is how can I connect to that database with a JDBC connection? I'm having issues with the whole "JDBC driver" deal really. Do I need a specific one or something? At first, I used one found by going to Control Panel > Admin Tools > ODBC Admin. Under System DSN I created a new Driver do Microsoft dBase. Gave it a name and used that in the con code. It connected a created a new database for me in my project directory. Obviously that isn't correct. Can anyone help me out?
hob hartman

Joined: Mar 04, 2002
Posts: 11
I would go to and download their MySqlODBC 2.50 driver. Then after installing the driver, go to control panel and the ODBC administrator dialog and set up your DSN using the MySQL driver that will now show up in the list. You will specify your db, username, password, and of course your DSN name. This driver is not JDBC driver but connects up with Sun's JDBC-ODBC driver bridge. I offer this since you mentioned the ODBC settings in the control panel.
Then you are set to do your code and connect to your db. Here is a little of my code to make my connection:
Connection con =null;
//selecting the driver as the JdbcOdbc driver
//create a connection to my MySql db using the DataSourceName in the ODBC
//dialog box in the Control Panel; my DSN is "WaltODBC", user is "", and password
//is "" Note: I downloaded the MySqlODBC 2.50 from MySQL web site
con=DriverManager.getConnection ("jdbc dbc:WaltODBC","","");
//create your statement object to carry your sql
Statement statement = con.createStatement();
//create your resultset;Human is a table in my db
ResultSet rs = statement.executeQuery(" SELECT * FROM Human");

Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
Thanks alot for your help. I figured out that I just needed to add the jar file holding the ODBC driver to my classpath.
I agree. Here's the link:
subject: Connecting to an existing db
It's not a secret anymore!