休息10天后重新看了下jdbc,开始振作继续学习(休息10天主要是因为驾照考试太累,2333),希望自己能够调整好心态,继续对程序有着一如既往的喜爱(加油)

Connection con=null;
Statement sm=null;
try {
//1.加载驱动
Class.forName("com.mysql.jdbc.Driver");
//2.创建链接
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/testkeyandforeigh", "root", "123456");
//3.创建statement或者preparedStatement【区别】
//主要用于发送sql语句
sm=con.createStatement();
//4.执行(srud操作,或者创建删除数据库等)
String sql="insert into category(cname) values ('socks')";
int rs=sm.executeUpdate(sql);//注意rs是返回值,返回的是更新的数量,更新一条数据返回1,2条数据返回2,删除失败应该返回0,删除成功返回1
if(rs==1) {
System.out.println("添加成功");
}
else {
System.out.println("添加失败");
} } catch (Exception e) {
e.printStackTrace();
}finally {
//关闭资源
try {
if (sm!=null) sm.close();
if (con!=null) con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

代码截图如上

最新文章

  1. Windows下wnmp相关配置
  2. LA 3942 - Remember the Word (字典树 + dp)
  3. bean找不到异常
  4. vue安装
  5. POJ 2796 Feel Good(单调栈)
  6. url中出现井号("#")的问题
  7. 关于Assets.car素材问题
  8. empty($w)
  9. iOS开发中的Get请求和POST请求
  10. windows下MySql没有setup.exe时的安装方法
  11. CAKeyframeAnimation
  12. Storm系列(九)架构分析之Supervisor-同步Nimbus的事件线程
  13. js中if的简写方法
  14. 使用CocoaPods出现 The `master` repo requires CocoaPods 0.32.1 - 问题解决
  15. PHP字节格式化
  16. (一)ORB描述子提取
  17. 外围功能电路控制 LET′S TRY“嵌入式编程”: 4 of 6
  18. <20180930>故障解决记录Cisco RV系列低端路由
  19. js精度误差
  20. SpringBoot整合EHcache学习笔记

热门文章

  1. Redis Desktop Manager连接Redis
  2. Centos下搭建golang环境
  3. 统计py文件中的代码行
  4. TCP/IP 最常见的错误原因码 (errno)列表
  5. httpclient新旧版本分割点4.3
  6. 11:vue-cli脚手架
  7. C# asp:FileUpload上传文件使用JS实现预览效果
  8. Restful framework【第九篇】分页器
  9. 我的互联网30年。永远的8U8 永远的Y365
  10. P2234 [HNOI2002]营业额统计(Splay树)题解