Java语言求一款小程序要求用到access数据库

2025-03-07 08:45:12
推荐回答(3个)
回答1:

操作界面如下:


运行用:java StdFrame即可。

回答2:

java语言连接access数据库,主要是加在access的驱动类,使用java的jdbc方式操作,实例如下:

package com.manager.common;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
 * c3p0 的 jdbc连接池
 * 
 * @author 森森
 * 
 */
public class DBConnectionPool {
    protected DBConnectionPool() {
    }
    private static ComboPooledDataSource ds = null;
    static {
        try {
            ds = new ComboPooledDataSource();
            // 设置jdbc的Driver类
            ds.setDriverClass("sun.jdbc.odbc.JdbcOdbcDriver");
            // 设置jdbc的url
            ds
                    .setJdbcUrl("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=H:/gyt_web/Database/SiteWeaver.mdb");
//            // 设置数据库的登录用户名
//            ds.setUser("admin");
//            // 设置数据库的登录用户名
//            ds.setPassword("admin");
            // 设置连接池的最大连接数
            ds.setMaxPoolSize(200);
            // 设置连接池的最小连接数
            ds.setMinPoolSize(20);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    protected static synchronized Connection getConnection() {
        Connection con = null;
        try {
            con = ds.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return con;
    }
    /**
     * 查询通用方法
     * 
     * @param sql
     * @param params
     * @return
     */
    public ResultSet query(String sql, Object[] params) {
        Connection conn = null;
        PreparedStatement ps教程tmt = null;
        ResultSet rs = null;
        conn = this.getConnection();
        try {
            pstmt = conn.prepareStatement(sql);
            if (params != null) {
                for (int i = 0; i < params.length; i++) {
                    pstmt.setObject(i + 1, params[i]);
                }
            }
            rs = pstmt.executeQuery();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return rs;
    }
    /**
     * 修改 增加 删除通用方法
     * 
     * @param sql
     * @param params
     * @return
     */
    public int executeSQL(String sql, Object[] params) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        int result = 0;
        conn = this.getConnection();
        try {
            pstmt = conn.prepareStatement(sql);
            if (params != null) {
                for (int i = 0; i < params.length; i++) {
                    pstmt.setObject(i + 1, params[i]);
                }
            }
            result = pstmt.executeUpdate();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        return result;
    }
}

回答3:

有一个进销存的 用的是access数据库