第七周JSP增删改查
2021-03-20 01:27
标签:package get list false ted ace add utils imp 第七周JSP增删改查 标签:package get list false ted ace add utils imp 原文地址:https://www.cnblogs.com/gsfwxj1820/p/12743547.htmlpackage ak74;
public class Haoshu {
package ak74;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.mysql.jdbc.Driver;
public class JDBCUtils {
//创建工具类 方便使用
//获取连接
public static Connection getCon() throws Exception{
Class.forName( "com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?useSSL=false", "root", "guoshaofeng");
return con;
}
//关闭数据流
public static void realse(ResultSet rst,Statement st,Connection con){
if(rst!=null){
try {
rst.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(st!=null){
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(con!=null){
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
package ak74;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class HaoshuDao {
private List
package ak74;
public class JdbcInsertText {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HaoshuDao dao=new HaoshuDao();
Haoshu haoshu=new Haoshu();
haoshu.setId(6);
haoshu.setName("兰亭集序");
haoshu.setMvp("王小姐");
haoshu.setChenghao("GXJ");
dao.insert(haoshu) ;
}
}
package ak74;
public class FindHaoshuByid {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HaoshuDao dao=new HaoshuDao();
Haoshu h= dao.FindHaoshuByid(6);
System.out.println(h.getName());
}
}
package ak74;
public class Update {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HaoshuDao dao=new HaoshuDao();
Haoshu hh=new Haoshu();
hh.setId(6);
hh.setName("徐凤年");
hh.setMvp("bl");
boolean b=dao.Update(hh);
System.out.println(b);
}
}
package ak74;
public class Delete {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HaoshuDao dao=new HaoshuDao();
boolean bb=dao.Delete(2);
System.out.println(bb);
}
}
/** * @param args */ //一,创建JavaBean用来封装用户数据 private int id; private String name; private String mvp; private String chenghao; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getMvp() { return mvp; } public void setMvp(String mvp) { this.mvp = mvp; } public String getChenghao() { return chenghao; } public void setChenghao(String chenghao) { this.chenghao = chenghao; } public static void main(String[] args) { // TODO Auto-generated method stub } }
下一篇:JS执行上下文栈