jsp连接数据库的.java文件 对语句求高手写出注释 麻烦了

packageckstudio.db;importjava.io.PrintStream;importjava.sql.*;publicclassfaq{StringsD... package ckstudio.db;

import java.io.PrintStream;
import java.sql.*;

public class faq
{

String sDBDriver = null;
String sConnStr = null;
Connection conn = null;
ResultSet rs = null;

public faq()
{
sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
sConnStr = "jdbc:odbc:hill";
conn = null;
rs = null;
try
{
Class.forName(sDBDriver);
}
catch(ClassNotFoundException classnotfoundexception)
{
System.err.println("faq(): " + classnotfoundexception.getMessage());
}
}

public void executeInsert(String s)
{
try
{
conn = DriverManager.getConnection(sConnStr);
Statement statement = conn.createStatement();
int i = statement.executeUpdate(s);
}
catch(SQLException sqlexception)
{
System.err.println("faq.executeUpdate:" + sqlexception.getMessage());
}
}

public ResultSet executeQuery(String s)
{
rs = null;
try
{
conn = DriverManager.getConnection(sConnStr);
Statement statement = conn.createStatement(1004, 1008);
rs = statement.executeQuery(s);
}
catch(SQLException sqlexception)
{
System.err.println("aq.executeQuery: " + sqlexception.getMessage());
}
return rs;
}

public void executeDelete(String s)
{
try
{
conn = DriverManager.getConnection(sConnStr);
Statement statement = conn.createStatement();
statement.executeUpdate(s);
}
catch(SQLException sqlexception)
{
System.err.println("faq.executeDelete: " + sqlexception.getMessage());
}
}

public int executeUpdate(String s)
{
int i = 0;
try
{
conn = DriverManager.getConnection(sConnStr);
Statement statement = conn.createStatement();
i = statement.executeUpdate(s);
}
catch(SQLException sqlexception)
{
System.err.println("faq.executeDelete: " + sqlexception.getMessage());
}
return i;
}

public void Close()
{
try
{
if(rs != null)
rs.close();
if(conn != null)
conn.close();
}
catch(SQLException sqlexception)
{
System.err.println("faq.executeDelete: " + sqlexception.getMessage());
}
}
}
展开
 我来答
cj64852093
2010-05-26 · 超过11用户采纳过TA的回答
知道答主
回答量:92
采纳率:0%
帮助的人:38.5万
展开全部
package ckstudio.db;

import java.io.PrintStream;
import java.sql.*;

public class faq
{

String sDBDriver = null;
String sConnStr = null;
Connection conn = null; //定义连接
ResultSet rs = null; //定义结果集

public faq()
{
sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; //驱动程序
sConnStr = "jdbc:odbc:hill";
conn = null; /*初始化变量
rs = null; */
try
{
Class.forName(sDBDriver); //加载驱动程序
}
catch(ClassNotFoundException classnotfoundexception) //捕获的异常
{
System.err.println("faq(): " + classnotfoundexception.getMessage()); //输入捕获的异常信息
}
}

public void executeInsert(String s) //插入语句块
{
try
{
conn = DriverManager.getConnection(sConnStr); //连接
Statement statement = conn.createStatement(); //创建状态集
int i = statement.executeUpdate(s); //对数据库进行添加操作
}
catch(SQLException sqlexception)
{
System.err.println("faq.executeUpdate:" + sqlexception.getMessage()); //捕获插入异常信息
}
}

public ResultSet executeQuery(String s) //查询语句块
{
rs = null;
try
{
conn = DriverManager.getConnection(sConnStr);
Statement statement = conn.createStatement(1004, 1008);
rs = statement.executeQuery(s); //对数据库进行查询操作
}
catch(SQLException sqlexception)
{
System.err.println("aq.executeQuery: " + sqlexception.getMessage()); //捕获查询异常信息
}
return rs;
}

public void executeDelete(String s) //删除语句块
{
try
{
conn = DriverManager.getConnection(sConnStr);
Statement statement = conn.createStatement();
statement.executeUpdate(s); //对数据块进行删除操作
}
catch(SQLException sqlexception)
{
System.err.println("faq.executeDelete: " + sqlexception.getMessage());
}
}

public int executeUpdate(String s) //修改语句块
{
int i = 0;
try
{
conn = DriverManager.getConnection(sConnStr);
Statement statement = conn.createStatement();
i = statement.executeUpdate(s); //对数据库进行修改操作
}
catch(SQLException sqlexception)
{
System.err.println("faq.executeDelete: " + sqlexception.getMessage());
}
return i;
}

public void Close()
{
try
{
if(rs != null) //判断结果集是否为空
rs.close(); //为空——关闭结果集
if(conn != null) //判断连接是否为空
conn.close(); //为空——断开连接
}
catch(SQLException sqlexception)
{
System.err.println("faq.executeDelete: " + sqlexception.getMessage());
}
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式