Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Error connecting to database

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Error connecting to database

    while trying to import some data from my accessing MS Access 2010 to a mySQL server i receive this error:

    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

    below is my code for the connection:

     String user = "root";
          String pwd = "pass";  
          String driver = "com.mysql.jdbc.Driver";
          String url = "jdbc:mysql://localhost:3306/newspaper";  
    try
           {
           	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           	String filename = "C:/JUN2011.mdb";
    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
    database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end 
    // now we can get the connection from the DriverManager
    Connection conn = DriverManager.getConnection( database ,"",""); 
     
            Class.forName(driver);
            Connection con = DriverManager.getConnection(url, user, pwd); 
            Statement stmt = con.createStatement();
    		Statement access=conn.createStatement();

    when i run the code in Win XP everything was working perfectly... but once i run it on Win 7.. the error came out..
    i am using;
    MySQL 5.5 server, MS Access 2010(on Win 7)/MS Access 2003 (Win XP).. my IDE is JCreator Pro 4.5
    OS: Window 7 x64bits Ultimate/ Windows XP Pro SP2


  2. #2
    Member
    Join Date
    Nov 2011
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Error connecting to database

    For MS Access, you need to define a data source. Maybe you defined it on WinXP but not yet on Win7.

    Spring 3
    Last edited by cafeteria84; January 22nd, 2012 at 04:00 PM.

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Error connecting to database

    Quote Originally Posted by cafeteria84 View Post
    For MS Access, you need to define a data source. Maybe you defined it on WinXP but not yet on Win7.
    my XP did not define a source name... also my code specify the access file through the filename variable...

  4. #4
    Member
    Join Date
    Nov 2011
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Error connecting to database

    Quote Originally Posted by bczm8703 View Post
    my XP did not define a source name... also my code specify the access file through the filename variable...
    Oh, sorry, I have just realized that, so are you sure that the file path is correct? Maybe it is moved around somewhere when you change to Win 7.

  5. #5
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Error connecting to database

    Quote Originally Posted by cafeteria84 View Post
    Oh, sorry, I have just realized that, so are you sure that the file path is correct? Maybe it is moved around somewhere when you change to Win 7.
    have already checked that and the path is correct...

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Error connecting to database

    1. Is java 32-bit installed on your machine?
    2. You have to create DNS by following,
    a). Go to Program Files (x86), System Files,(somewhere, i don't know the exact path) Find for odbcad32.exe and double click
    3. Now create DNS and again execute the code.

  7. #7
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Error connecting to database

    Quote Originally Posted by Mr.777 View Post
    1. Is java 32-bit installed on your machine?
    2. You have to create DNS by following,
    a). Go to Program Files (x86), System Files,(somewhere, i don't know the exact path) Find for odbcad32.exe and double click
    3. Now create DNS and again execute the code.
    do u mean DNS or DSN? as i could not find any DNS in the odbcad32.exe

    oh and i sure java is being install as the connecting to mySQL is fine... the error only occur when i try to connect to MS Access...

  8. #8
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Error connecting to database

    Yeah i mean DSN. And i told you the process, connect by using odbcad32.exe in Syswow64 folder.

  9. #9
    Member
    Join Date
    Mar 2011
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Error connecting to database

    Quote Originally Posted by Mr.777 View Post
    Yeah i mean DSN. And i told you the process, connect by using odbcad32.exe in Syswow64 folder.
    sorry for asking this... but i still need to specify the DSN??? caouse i m connecting to the access using a path method.. and my XP did not perform this type and it works

  10. #10
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Error connecting to database

    I will recommend you to read This

Similar Threads

  1. Problem With Applet Connecting With Microsoft Access Database
    By Saurabh Mittal in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 29th, 2011, 10:43 AM
  2. Connecting to Access 2007 Database
    By aussiemcgr in forum JDBC & Databases
    Replies: 12
    Last Post: December 14th, 2010, 04:42 PM
  3. Looking at Exploring Database Connecting
    By aussiemcgr in forum JDBC & Databases
    Replies: 2
    Last Post: August 12th, 2010, 03:40 PM
  4. Connecting to Cache through JDBC - error
    By javavick in forum JDBC & Databases
    Replies: 0
    Last Post: May 6th, 2010, 06:34 AM
  5. Connecting to a database
    By fwashington in forum JDBC & Databases
    Replies: 5
    Last Post: March 15th, 2010, 01:37 PM