当前位置:编程学习 > JAVA >>

java工具类

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();
}
}
}
--------------------编程问答-------------------- 除 --------------------编程问答-------------------- --------------------编程问答-------------------- 先森,你想说明啥··· --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 楼主大概是想写个博客的吧,结果发成提问帖了 --------------------编程问答--------------------
引用 6 楼 vsddvsd 的回复:
楼主大概是想写个博客的吧,结果发成提问帖了

+++ --------------------编程问答-------------------- --------------------编程问答-------------------- 来散粉的吧 ? 我接! 哈哈 --------------------编程问答-------------------- 写了个工具类贴上来是几个意思 ? --------------------编程问答--------------------
引用 7 楼 lyh_974056553 的回复:
引用 6 楼 vsddvsd 的回复:楼主大概是想写个博客的吧,结果发成提问帖了
+++

发帖应该写点说明吧 --------------------编程问答-------------------- 没看懂楼主想干嘛 --------------------编程问答-------------------- --------------------编程问答-------------------- 然后呢?               --------------------编程问答-------------------- 新年快乐。 嘻嘻。  不知道 你什么问题。 我觉得是拜年帖、 --------------------编程问答-------------------- 这样看代码有点痛苦。。。。。。
不过楼主新年快乐。。 --------------------编程问答-------------------- 简单的数据库访问 --------------------编程问答-------------------- 楼主大概是想写个博客的吧,结果发成提问帖了  --------------------编程问答-------------------- 楼主,你到底要干嘛? --------------------编程问答-------------------- 无解呀,无解       --------------------编程问答-------------------- 新年快乐!看不懂楼主的意思?
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,