import java.sql.*;
public class DBconn
{
String DBDriver = "org.gjt.mm.mysql.Driver";
String ConnStr = "jdbc:mysql://localhost/db";
String MyUser = "root";
String MyPassword = "";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
public DBconn()
{
try
{
Class.forName(DBDriver);
} catch (java.lang.ClassNotFoundException e)
{
System.err.println("DBconn (): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
rs = null;
try
{
conn = DriverManager.getConnection(ConnStr, MyUser, MyPassword);
Statement stmt = conn.createStatement(
java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
} catch (SQLException ex)
{
System.err.println("aq.executeQuery:" + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
{
try
{
conn = DriverManager.getConnection(ConnStr, MyUser, MyPassword);
Statement stmt = conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
} catch (SQLException ex)
{
System.err.println("aq.executeQuery:" + ex.getMessage());
}
}
}
public boolean closeConn()
{
try
{
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
return true;
} catch (SQLException ex)
{
System.err.println("closeConn:" + ex.getMessage());
return false;
}
}
}
posted on 2007-09-15 12:59
jadmin 阅读(144)
评论(0) 编辑 收藏