业余程序员如何理解JAVABEAN数据库连接
问题一:如题
问题二:实例求解
////////////////////////////
数据库连接的的JAVABEAN,Query()和executeSq()是否多余?其他是否有不妥?
///////////////////////////
package dbcon;
import java.sql.*;
import java.io.*;
public class GetValue{
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
public GetValue(){
try{
if (rs!=null)
rs.close();
if (stmt!=null)
stmt.close();
if (conn!=null)
conn.close();
}catch(
SQLException ex)
{
System.err.println( "DBCONN: " + ex.getMessage());
}
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
}catch(
java.lang.ClassNotFoundException e){
}
}
public ResultSet executeQuery(String sql){
rs = null;//这个rs是否和JSP中定义的rs一样
try{
if (rs!=null)
rs.close();
if (stmt!=null)
stmt.close();
if (conn!=null)
conn.close();
}catch(SQLException ex)
{
return rs;
}
try{
conn= DriverManager.getConnection( "jdbc:odbc:netschool ");
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}catch(SQLException ex){
}
return rs;
}
public ResultSet Query(String sql){
rs = null;
try{
conn= DriverManager.getConnection( "jdbc:odbc:netschool ");
&n