package com.ck.DButil;
import java.sql.*;
public class DButil {
private static Connection conn=null;
private static PreparedStatement ps=null;
private static ResultSet rs=null;
public static PreparedStatement getPs(String sql){
try {
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/shop?" +
"relaxAutoCommit=true&zeroDateTimeBehavior=convertToNull";
String user="root";
String password="root";
conn=DriverManager.getConnection(url, user, password);
ps = conn.prepareStatement(sql);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ps;
}
public static int executeUpdate(){
int a=0;
try {
a=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return a;
}
public static ResultSet executeQuery(){
try {
rs=ps.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public static void close(){
try {
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();
}
if(conn!=null){
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

解决方案 »

  1.   

    楼主大概是想写个博客的吧,结果发成提问帖了
      

  2.   

    来散粉的吧 ? 我接! 哈哈
      

  3.   

    写了个工具类贴上来是几个意思 ?
      

  4.   

    然后呢?              
      

  5.   

    新年快乐。 嘻嘻。  不知道 你什么问题。 我觉得是拜年帖、
      

  6.   

    这样看代码有点痛苦
    不过楼主新年快乐。。
      

  7.   

    楼主大概是想写个博客的吧,结果发成提问帖了 
      

  8.   

    无解呀,无解      
      

  9.   

    新年快乐!看不懂楼主的意思?