package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Test {

public static void main(String[] args) {
//1.加载驱动
Connection conn = null;
Statement sm = null;
try {
Class.forName("com.mysql.jdbc.Driver");

//2.获得数据库连接
String url = "jdbc:mysql://localhost:3306/epet";

conn = DriverManager.getConnection(url, "root", "root");

//3.发送SQL语句,获得结果
sm = conn.createStatement();
/*Scanner input = new Scanner(System.in);
System.out.println("输入狗的名称:");
String name = input.next();
System.out.println("输入狗的健康值:");
int health = input.nextInt();
System.out.println("输入狗的亲密度:");
int love = input.nextInt();
System.out.println("输入狗的品种:");
String strain = input.next();

String sql = "INSERT INTO dog(NAME,health,love,strain) VALUES ('"+name+"',"+health+","+love+",'"+strain+"')";
*/
String updateSql = "update dog set health = 100 where id=1";

String deleteSql = "delete from dog where id = 1";
//4.处理结果
//int count = sm.executeUpdate(sql);
//int count = sm.executeUpdate(updateSql);
int count = sm.executeUpdate(deleteSql);
if(count > 0) {
//System.out.println("数据插入成功!");
//System.out.println("数据修改成功!");
System.out.println("数据删除成功!");
} else {
//System.out.println("数据插入失败!");
//System.out.println("数据修改失败!");
System.out.println("数据删除失败!");
}

//System.out.println("连接成功!");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
//5.释放资源
try {
conn.close();
sm.close();
} catch (SQLException e) {
e.printStackTrace();
}

}

}

}

最新文章

  1. Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with value '"*, Microsoft.AspNet.Mvc.TagHelpers"'
  2. c# 使用正则表达式 提取章节小说正文全本篇
  3. PHP中有关Session的函数比较多,最常用到的也就这么几个函数
  4. php配置相关
  5. Hibernate之继承映射
  6. Jersey(1.19.1) - Client API, Uniform Interface Constraint
  7. poj 1274 The Perfect Stall【匈牙利算法模板题】
  8. CMMI-4中19个PA的大致描述
  9. Codeforces 429E Points and Segments
  10. 背包问题(01背包,完全背包,多重背包(朴素算法&&二进制优化))
  11. 微信小程序如何使用iconfont阿里巴巴图标库?
  12. DevExpress Grid使用checkBox选中的方法
  13. for循环输出漏斗的形状【java】
  14. Selenium WebDriver Api 知识梳理
  15. Kubernetes K8s
  16. Java基础——网络编程(二)
  17. 2.Hibernate的主配置文件hibernate.cfg.xml
  18. Fig 7.2.4 & Fig 7.3.2
  19. 利用python操作mrjob实例---wordcount
  20. 移动端web页面input限制只能输入数字

热门文章

  1. HDU2181(KB2-C)
  2. 小tip:CSS3下的渐变文字效果实现——张鑫旭
  3. 利用GDAL从内存中直接解析图像数据
  4. jQuery轮播图(手动点击轮播)
  5. 带你从零学ReactNative开发跨平台App开发(十一)
  6. scp远程传输文件和ssh远程连接
  7. select2加载远程数据示例
  8. Oracle EBS AP 供应商地点失效
  9. [WinCE] Win CE 屏幕截图
  10. Script:when transaction will finish rollback