帮我找找这个连接Mysql数据库Bean的错误
package dbBean;
import java.sql.*;
public class MySqlBean
{
private Connection conn = null;
private Statement stmt = null;
ResultSet rs = null;
public void openConn(String dsn, String uid, String pwd)throws Exception
{
try
{
uid= "root ";
pwd= " ";
dsn= "jdbc:mysql://localhost:3306/books?useUnicode=true&characterEncoding=gbk ";
Class.forName( "org.gjt.mm.mysql.Driver ");
conn = DriverManager.getConnection(dsn+ "?user= "+uid+ "&password= "+pwd+ "&useUnicode=true&characterEncoding=gbk ");
}
catch(Exception e)
{
System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
rs = null;
try
{
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql)
{
int reslut = 0;
stmt = null;
try
{
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
reslut = stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return reslut;
}
public void closeStmt()
{
try
{
stmt.close();
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
}
public void closeConn()
{
try
{
conn.close();
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
}
}
[解决办法]
这样的工作,交给编译器把!!