javabean java类

dilanfeixue 2012-10-25 11:08:43
package com.gx.bean;
import java.sql.*;

public class conn {
public Connection getconn() throws SQLException{
Connection conn=null;
try{
Class.forName("com.mysql.jdbc.odbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","123456");
}
catch(ClassNotFoundException e){
e.printStackTrace();

}
catch(SQLException e){
e.printStackTrace();
}
return conn;



}
public PreparedStatement prepare(Connection conn , String sql){
PreparedStatement pstmt=null;
try{
if(conn!=null){
pstmt=conn.prepareStatement(sql);
}
}catch(SQLException e){
e.printStackTrace();

}


return pstmt;


}

public Statement getStatement (Connection conn){
Statement stmt=null;
try{
if(conn != null)
{
stmt=conn.createStatement();
}

}catch(SQLException e)
{
e.printStackTrace();

}
return stmt;
}


public ResultSet getResultSet(Statement stmt, String sql){
ResultSet rs=null;
try{
if(stmt!=null){

rs=stmt.executeQuery(sql);
}
}
catch(SQLException e){
e.printStackTrace();

}
return rs;



public void executeUpdate(Statement stmt, String sql){//问题出在这里请大家看看 问题在哪里?

try{
if(stmt!=null){
stmt.executeQuery(sql);
}
}catch(SQLException e){
e.printStackTrace();
}
}


}

public void close(Connection conn){
try{
if(conn!=null){
conn.close();
conn=null;

}
}catch(SQLException e){
e.printStackTrace();
}
}


public void close(Statement stmt){
try{
if(stmt!=null){
stmt.close();
stmt=null;

}
}catch(SQLException e){
e.printStackTrace();

}
}
public void close (ResultSet rs){
try{
if(rs!=null){
rs.close();
rs=null;
}
}
catch(SQLException e){
e.printStackTrace();
}
}



}
...全文
208 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
dw_java08 2012-10-26
  • 打赏
  • 举报
回复
楼主什么意思?是代码编译错误还是运行错误还是让大家帮你检查代码? 你要把你的问题描述清楚。这样才能帮你解决问题。
asdf544265772 2012-10-26
  • 打赏
  • 举报
回复
嘛意思 呀
路过吧。。。。。
chen505586338 2012-10-26
  • 打赏
  • 举报
回复
额。。异常也没有。坐等高人
kb112kb 2012-10-26
  • 打赏
  • 举报
回复
正在学习中,,也不懂
dxqrr 2012-10-25
  • 打赏
  • 举报
回复
这......
long95wang 2012-10-25
  • 打赏
  • 举报
回复
你的异常信息贴出来啊,这样看只能怀疑下你的sql语句有问题。
Flycutter 2012-10-25
  • 打赏
  • 举报
回复
我囧,就一句注释啊,好歹有个结果或者是堆栈信息啥的啊

62,621

社区成员

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

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