连接数据库Connection

public class Basedao {static{//加载驱动try {Class .forName("com.mysql.cj.jdbc.Driver");//加载驱动程序} catch (ClassNotFoundException e) { //捕捉驱动类未找到异常e.printStackTrace();//输出异常信息}}public static Connection getconn(){//创建一个连接对象Connection conn=null;try {conn= DriverManager.getConnection("jdbc:mysql://localhost:8080/mall?useSSL=false&serverTimezone=UTC","root","123456");//连接数据库路径,用户名,密码} catch (SQLException e) {e.printStackTrace();}return conn;//返回获取到的数据库连接对象}public static int executeIUD(String sql ,Object[] params){int count=0;Connection conn=Basedao.getconn(); //连接数据库//准备SQLPreparedStatement ps =null;//insert into user("""","")value(?,?,?)try {//准备SQLps=conn.prepareStatement(sql);   //创建语句//遍历参数for (int i=0;i


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部