Results 1 to 5 of 5
  1. #1
    ArneBassez is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default jdbc-odbc cannot connect

    Hi,

    I'm using a standard connection code for jdbc-odbc.

    But I keep getting:

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

    -I've done everything on the microsoft page. (regedt32.exe : OCDB.INI set permissions to all, but no DSNName visible..also MAKER EIGENAAR doesnt have permission, - in english MAKER OWNER)
    -uninstalled access, installed New Database Manager for office 64bit and reinstalled access.
    - downloaded MDAC_TYP for 32-bit drivers.
    -Changed permissions in control panal - data source . Also changed Target and Start
    - changed location of my database to c:/users/Arne instead of C: since I always need to give authorization to write there.

    if I execute: c:\windows\sysWOW64\odbcad32.exe I see all drivers

    I get the message that driver is loaded, so I don't think problem is there, more likely in the authorization department :)...

    This is really driving me crazy, spent many hours trying to fix it. And it might be an easy solution.

    Just to be sure, here is my code:):

    Java Code:
    package Database;
    
    import java.sql.*;
    
    public class Database {
    
    private Connection dbConnection;
    
        //constructor
        public Database(String dbFile)
        {
            loadDriver();
            connectDatabase(dbFile);
        }
    
        //driver laden
        private void loadDriver()
        {
            try
            {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                System.out.println("Laden van de driver is gelukt.");
            }
            catch (ClassNotFoundException e)
            {
                System.out.println("Kan de driver niet in de classpath vinden.");
                e.printStackTrace();
                System.exit(1);
            }
        }
    
        //connectie tot stand brengen
        private void connectDatabase(String dbFile)
        {
            try
            {
                String protocol = "jdbc";
                String subProtocol = "odbc";
                String subName = "Driver={Microsoft Access Driver (*.mdb,*.accdb)}; " + "DBQ=" + dbFile;
                String URL = protocol + ":" + subProtocol + ":" + subName;
    
                dbConnection = DriverManager.getConnection(URL);
            }
            catch (SQLException error)
            {
                System.err.println("Error connecting to database: " +
                                   error.toString());
            }
        }
    
        public Connection getDbConnection()
        {
            return dbConnection;
        }
    
        public void closeConnection()
        {
            try
            {
                dbConnection.close();
            }
            catch (SQLException error)
            {
                System.err.println("Cannot disconnect database");
            }
        }
    
    }
    Last edited by ArneBassez; 12-08-2010 at 03:54 AM.

  2. #2
    demonick is offline Member
    Join Date
    Dec 2010
    Posts
    27
    Rep Power
    0

    Default

    Either database is not found, wrong name/URL or security issues.

  3. #3
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    4

    Default

    Please use code tags [CODE] [/CODE] .


    Did you put password on your database? If yes, you have to give the username and password when trying to
    connect in database.

    Java Code:
    [b]EXAMPLE:[/b]
    dbConnection = DriverManager.getConnection(URL, "myUSERNAME", "myPASSWORD");
    Last edited by mine0926; 12-08-2010 at 02:20 AM.

  4. #4
    ArneBassez is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    No, there is no password on my MS access database.

    I have no problem making a connection on my old computer with the same database and program.

  5. #5
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    4

    Default

    Check the path that you input and the actual location of your database.

Similar Threads

  1. Replies: 1
    Last Post: 07-23-2010, 09:23 AM
  2. Replies: 3
    Last Post: 03-28-2010, 06:55 AM
  3. Connect to Access without MS ODBC?
    By ribbs2521 in forum New To Java
    Replies: 5
    Last Post: 04-16-2009, 03:33 AM
  4. Help me this error in JDBC-ODBC connection
    By lordelf in forum Java Servlet
    Replies: 3
    Last Post: 04-04-2009, 08:37 AM
  5. Using JDBC-ODBC bridge
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 09:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •