关于在http://www.microsoft.com/sql/downloads/2000/jdbc.asp下载的MS SQL JDBC的其他问题

java_prince 2001-10-25 09:34:56
从http://www.microsoft.com/sql/downloads/2000/jdbc.asp下载的MS SQL JDBC安装了以后,如何使用?具体语句如何写呢?
...全文
149 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
园艺爱移动 2001-10-26
  • 打赏
  • 举报
回复
最好用WINRAR解压后,放到一个专用目录,再把环境变量CLASSPATH 加上你的目录.这样就能使用了.
代码:(先写一个关于数据的bean , 后面的事应该不用说了吧!)
public DBconnect() {
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection(address,user,passwd);
}catch(Exception fs)
{
fs.printStackTrace();
}
}

/**
* 函数名称:executeQuery
* 功能:执行sql查询语句
* 参数:String: sql语句
* 返回:ResultSet:查询得到的结果集
*/
public ResultSet executeQuery(String sql){
System.err.print("DBsql111"+sql) ;
try{
con = DriverManager.getConnection(address,user,passwd);
stmt=con.createStatement();
return stmt.executeQuery(sql);
}catch(Exception gr)
{
gr.printStackTrace();
return null;
}
}

/**
* 函数名称:executeUpdate
* 功能:执行sql更新语句
* 参数:String: sql语句
* 返回:int:更新纪录的数目
*/
public int executeUpdate(String sql){
try{

if(stmt!=null)
stmt.close();
if(con==null)
con = DriverManager.getConnection(address,user,passwd);
stmt=con.createStatement();
return stmt.executeUpdate(sql);
}catch(Exception sg){
sg.printStackTrace();
return 0;
}
}

/**
* 函数名称:close
* 功能:关闭状态集和结果集
* 参数:无
* 返回:无
*/
public void close(){
try{
if(stmt!=null)
stmt.close();
con.close();
con=null;
stmt = null;
}catch(Exception ws)
{
ws.printStackTrace();
}
}
}

wenxue 2001-10-25
  • 打赏
  • 举报
回复
online books 上有详细介绍

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧