Removal of JDBC ODBC bridge in java 8

前端 未结 5 800
Happy的楠姐
Happy的楠姐 2020-11-22 15:42

Starting with Java 8, the JDBC-ODBC Bridge will no longer be included with the JDK.

Class.forName(\"sun.jdbc.odbc.JdbcOdbcDriver\"); // classNotFoundExceptio         


        
5条回答
  •  旧巷少年郎
    2020-11-22 15:57

    I found a reasonable solution that allows for use of existing code with a change only to open database connection logic.

    UCanAccess is an open-source, JDBC driver.

    http://ucanaccess.sourceforge.net/site.html

    That has two dependencies, one of which has two more dependencies.

    jackcess-2.0.0.jar or later

    commons-lang-2.4.jar
    
    commons-logging-1.0.4.jar
    

    hsqldb.jar(2.2.5)

    Those are all open-source. Do an internet search, download, unzip if necessary and put all four jars plus the one for UCanAccess in a directory in your project (e.g. JDBC-to-MSAccess). If using Ecplise, add to your build path by choosing from the menu "Project / Properties / Java Compiler / Libraries / Add External JARs" and select all five jar files.

    The connection logic is really simple:


    String strConnectionString = "";
    Connection conAdministrator = null;
    
    // Register driver
    Class.forName( "net.ucanaccess.jdbc.UcanaccessDriver" );
    
    // System.getProperty( "user.dir" ) => Current working directory from where application was started
    
    strConnectionString = "jdbc:ucanaccess://" + System.getProperty( "user.dir" )  + "\\Your-database-name.";
    
    // Open a connection to the database
    conAdministrator = DriverManager.getConnection( strConnectionString );
    

提交回复
热议问题