类函数内容如下
package org.crazyit.hrsystem.dao;
import java.sql.*;
import java.util.Hashtable;
import java.util.List;
public class uploadDAOImpl {
static Connection conn;
static Statement st;
//?insert,update,query,delete
public static Connection getConnection() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost/etest_db";
conn = DriverManager.getConnection(
url, "root", "sa");
System.out.println("success!");
} catch (Exception e) {
System.out.println("连接失败" + e.getMessage());
}
return conn;
}
public void insert(String sql){
conn=getConnection();
int count=0;
Statement stmt=null;
try{
stmt=conn.createStatement();
count=stmt.executeUpdate(sql);
System.out.println("插入 " + count + " 条数据");
conn.close();
}catch(Exception e){
System.out.println("插入数据失败"+e.getMessage()+";sql="+sql);
}
}
public static void update() {
conn = getConnection();
try {
String sql = "update resource set wage='23000' where name = 'Tom1'";
st = (Statement) conn.createStatement();
int count = st.executeUpdate(sql);
System.out.println("recourse提交 " + count + " 数据");
conn.close();
} catch (SQLException e) {
System.out.println("提交数据失败");
}
}
public static ResultSet query1(String sql){
conn=getConnection();
ResultSet res=null;
try{
st=conn.createStatement();
res=st.executeQuery(sql);
}catch(SQLException e){
System.err.println("失败:" + e.getMessage() + ";sql=" + sql);
return null;
}
return res;
}
public static void delete() {
conn = getConnection();
try {
String sql = "delete from resource where name = 'lili'";
st = (Statement) conn.createStatement();