JDBC技术

1.加载数据库驱动

<span style="font-size:14px;">Class.forName("com.mysql.jdbc.Driver");</span>
2.连接数据库

<span style="font-size:14px;">Connection con=DriverManager.getConnection("jdbc:mysql://localhost/test_db","sa","123456");</span>

3.向数据库发送SQL语句

<span style="font-size:14px;">// statement用来执行SQL语句
Statement statement = conn.createStatement();
// 要执行的SQL语句
String sql = "select * from test_user";
//向服务器插入数据
statement.executeUpdate(sql1);
// 结果集
ResultSet rs = statement.executeQuery(sql);</span>

4.DriverManager类

  • getConnection(String url,String user,String password);   //数据库的URL,用户名,密码
  • setLoginTimeout(seconds);  //等待最长时间
  • println(String message);  //将一条消息打印到当前的JDBC日志流中

5.Connection接口

6.Statement接口

  • execute(String sql)    执行静态的select语句,该语句可能返回多个结果集
  • executeQuery(String sql)    执行给定的SQL语句,该语句返回ResultSet对象
  • clearBatch()     清空   Statement  对象的当前SQL命令列表
  • executeBatch()     
  • executeUpdate()     执行SQL语句,该语句以insert、update、delete
  • addBatch()     将命令列表添加到当前的Statement  对象
  • close()

7.PreparedStatement 接口

8.ResultSet 接口

以上这些都要去看帮助文档


1.向数据库添加数据

<span style="font-size:18px;">String sql1 = "insert into test_user(id,name,password) value('3','jack','abc123')";
statement.executeUpdate(sql1);</span>
statement.execute("insert  into  test_user  value('3','jack','123456')");
statement.executeUpdate("insert into test_user value("'+3+'",'"+name+"','"+password+"')");
2.删除数据

statement.executeUpdate("delete from test_user where id>2");
3.修改数据






  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值