JAVA 【ACCESS数据库能读不能写】大家救救我吧.★★【up有分,高分求解】
/////////////////////////////////////////////////////////
//////这是连接数据库的文件./////////////////////////////
ACCESS数据库+java
///////////////////////////////////////////////////////
package football;
import java.sql.*;
import java.io.*;
public class DbConnection {
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
private String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
private String sConnStr = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=league.mdb";
public DbConnection() {
}
public void connectionOpen()
{
try {
Class.forName(sDBDriver);
}
catch (java.lang.ClassNotFoundException e) {
System.err.println(e.getMessage());
}
}
//executeQuery and executeUpdate
public ResultSet executeQuery(String query) throws SQLException{
conn = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
rset = stmt.executeQuery(query);
return rset;
}
public void executeUpdate(String query) throws SQLException{
stmt = conn.createStatement();
stmt.executeUpdate(query);
if(stmt != null) stmt.close();
}
public void close() throws SQLException{
if(conn != null) conn.close();
if(rset != null) rset.close();
if(stmt != null) stmt.close();
}
protected void finalize() throws Throwable{
close();
}
}