用java编的连接access数据库代码在运行中提示:查询中的数目与目标字段中的数目不同!怎么解决?
- 提问者网友:听门外雪花风
- 2021-04-12 00:40
- 五星知识达人网友:行雁书
- 2021-04-12 01:32
package util;
import java.io.*;
import java.util.*;
import java.sql.*;
public class DBPool{
private static DBPool instance = null;
//取得连接
public static synchronized Connection getConnection() {
if (instance == null){
instance = new DBPool();
}
return instance._getConnection();
}
private DBPool(){
super();
}
private Connection _getConnection(){
try{
String sDBDriver = null;
String sConnection = null;
String sUser = null;
String sPassword = null;
Properties p = new Properties();
InputStream is = getClass().getResourceAsStream("/db.properties");
p.load(is);
sDBDriver = p.getProperty("DBDriver",sDBDriver);
sConnection = p.getProperty("Connection",sConnection);
sUser = p.getProperty("User","");
sPassword = p.getProperty("Password","");
Properties pr = new Properties();
pr.put("user",sUser);
pr.put("password",sPassword);
pr.put("characterEncoding", "GB2312");
pr.put("useUnicode", "TRUE");
Class.forName(sDBDriver).newInstance();
return DriverManager.getConnection(sConnection,pr);
}
catch(Exception se){
System.out.println(se);
return null;
}
}
//释放资源
public static void dbClose(Connection conn,PreparedStatement ps,ResultSet rs)
throws SQLException
{
rs.close();
ps.close();
conn.close();
}
}
看看是不是你写连接ACCESS数据库的类有问题啊
- 1楼网友:过活
- 2021-04-12 02:59