首页 > 数据库技术 > 详细

JAVA链接数据库 增删改查

时间:2021-07-17 11:08:08      阅读:21      评论:0      收藏:0      [点我收藏+]


//加载驱动
Class.forName("com.mysql.jdbc.Driver");

//获得url 账户密码 获得链接
Connection connection=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/bookmng?useUnicode=true&characterEncoding=utf-8", "root", "root123");
System.out.println(connection);

 

// // 增
// String sql="insert into book_table(book_name,book_author,book_price)"+"values(?,?,?)";
// PreparedStatement statement=(PreparedStatement) connection.prepareCall(sql);
// statement.setString(1, "三国");
// statement.setString(2, "罗贯中");
// statement.setInt(3, 90);
// statement .executeUpdate();



     String sql1="delete from book_table where book_id=?";
  PreparedStatement statement1=(PreparedStatement) connection.prepareCall(sql1);
  statement1.setInt(1, 2);
  statement1 .executeUpdate();




//改

String sql="update book_table set book_author =? where book_id=?";
PreparedStatement statement=(PreparedStatement) connection.prepareStatement(sql);
statement.setString(1, "gg");
statement.setInt(2,10 );
statement.executeUpdate();

 

JAVA链接数据库 增删改查

原文:https://www.cnblogs.com/-yby-970205/p/15022543.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!