本文介绍了连接访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



import java.sql.*;
public class Main
{
    private static final String accessDBURLPrefix = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
    private static final String accessDBURLSuffix = ";DriverID=22;READONLY=false}";
    // Initialize the JdbcOdbc Bridge Driver
    static {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch(ClassNotFoundException e) {
            System.err.println("JdbcOdbc Bridge Driver not found!");
        }
    }
    public static Connection getAccessDBConnection(String filename) throws SQLException {
        String databaseURL = accessDBURLPrefix + filename + accessDBURLSuffix;
        return DriverManager.getConnection(databaseURL, "", "");
    }
    public static void main(String[] args)
    {
        try
        {
            Connection conn = getAccessDBConnection("User.mdb");
            Statement s = conn.createStatement();
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
}

推荐答案


这篇关于连接访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 08:27