比较子自好的代码

public void Zen2(String typename, String title, String content) {
try {
DBTools tools = new DBTools();
Connection conn = tools.getConnection();
String sql1 = "select typeid from acticle_type where typename=?";// 根据名字最后转化成Typeid;
PreparedStatement pre1 = conn.prepareStatement(sql1);
pre1.setString(1, typename);
ResultSet set = pre1.executeQuery();
//set.getString(1);不用set.next
set.next() ;
String typeid = set.getString(1);
System.out.println(typeid);
String sql = "insert into acticle (acticleid,title,content,typeid) values(?,?,?,?)";
PreparedStatement pre = conn.prepareStatement(sql);
pre.setInt(1, ZenDAO.getMax2());
pre.setString(2, title);
pre.setString(3, content);
pre.setString(4, typeid);
pre.execute();

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

}






public void San1(String typeid) {
try {
DBTools tool = new DBTools();
Connection conn = tool.getConnection();
String sql ="delete acticle_type where typeid=?";
System.out.println(sql);
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1,typeid);
System.out.println(typeid);
ps.execute();
String sql1="delete acticle where typeid=?";
System.out.println(sql1);
PreparedStatement ps1 = conn.prepareStatement(sql1);
ps1.setString(1, typeid);
ps1.execute();
System.out.println(typeid);
ps.execute();
} catch (SQLException e) {
e.printStackTrace();
}

你可能感兴趣的:(sql)