SQL connection...

Ok, let's say I have an access DB in the same folder as my java program...  What's the connection statement I put to get to the database?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Below is a step-by-step example on how to connect to an Access database.  As you can see you first need to establish a data source and then write the code to connect.
The statement that actually connects your java program to the data source (and in turn.. the database) is:
con = DriverManager.getConnection(url, "", "");

   Before you can communicate between JDBC and Access you need to create a data source.
   You do this by going into the Control Panel and clicking on ODBC icon. (if you dont have an ODBC icon
   you will need to reinstall Access)
   Here are the steps to create the data source once you are in the ODBC icon:
   1) click add
   2) then specify what driver to use... for this case click Access -- then finish
   3) specify the data source name
   4) if you have a mdb file already click select.. otherwise click create
   you should now have a data source for comunication and a database to send/receive info to/from.
   You may want to check the code to make sure there is a Class.forName() line in it
   below is some test code...
   it simply creates a table.. code taken from the Java Tutorial
   datasource is called "coffee"
   import java.sql.*;

   public class CreateCoffees {
       public static void main(String args[]) {
           String url = "jdbc:odbc:coffee";
           Connection con;
           String createString;
           createString = "create table COFFEES " +
                               "(COF_NAME VARCHAR(32), " +
                               "SUP_ID INTEGER, " +
                               "PRICE FLOAT, " +
                               "SALES INTEGER, " +
                               "TOTAL INTEGER)";
           Statement stmt;

           try {
           } catch(java.lang.ClassNotFoundException e) {
               System.err.print("ClassNotFoundException: ");

           try {
               con = DriverManager.getConnection(url, "", "");
               stmt = con.createStatement();

           } catch(SQLException ex) {
               System.err.println("SQLException: " + ex.getMessage());

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The above code comes from the Java Tutorial (I'll give credit where credit is due).
The Java Tutorial has a JDBC tutorial.  Its far from complete but it gives you the basics.

Hi Conick,

 I think U are calm in the site for three months. I did n't find any Ur comments except for last 2 weeks since 3 months i entered. Is it???

I was completely swamped for awhile so I couldnt leave my usual wordy comments containing little helpful information.
Thanks for noticing my return. :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.