那里有封装好的操作数据库的BEANS代码??

wujevons 2001-10-18 05:19:24
我写的老是不行,执行后会使SQLSERVER没有响应。。。 Exception是如何处理的??
...全文
92 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
skt985 2002-01-11
  • 打赏
  • 举报
回复
40566关注!
wujevons 2001-10-19
  • 打赏
  • 举报
回复
昨天下班了,今天早上来改成我的SQL连接试了一下,成了,,我以前没做过JAVA..方法上不太熟练。。嘿嘿。。送分
vincentmax 2001-10-18
  • 打赏
  • 举报
回复
我也想要~~~
czb 2001-10-18
  • 打赏
  • 举报
回复
不会吧?这么夸张?!我写得不好,如果你不介意,可以参考下我的吧,不过是业余水平的拉。
import java.util.*;
import java.sql.*;
import java.io.*;
import java.sql.*;

public class mysql {
Connection conn=null;
Statement statement=null;
PreparedStatement pstmt=null;
ResultSet rs=null;

public mysql(){
try{
Class.forName("org.gjt.mm.mysql.Driver");
}catch(ClassNotFoundException e)
{System.err.println("mysql():"+e.getMessage());}

String url="jdbc:mysql://localhost:3306/Sample?user=root;password=";
try{
conn=DriverManager.getConnection(url);
statement = conn.createStatement();
}catch(SQLException sqlEx)
{System.err.println(sqlEx.getMessage());}
}

public ResultSet executeQuery(String sql)
{
try{
rs = statement.executeQuery(sql);
}catch(SQLException ex)
{
System.err.println("executeQuery():"+ex.getMessage());
}
return rs;
}

public int executeUpdate(String sql)
{
int i=0;
try{
i = statement.executeUpdate(sql);
}catch(SQLException ex)
{
System.err.println("executeUpdate():"+ex.getMessage());
}
return i;
}
}
wujevons 2001-10-18
  • 打赏
  • 举报
回复
参考一下

81,122

社区成员

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

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