jdbc 回顾
2024-10-20 01:37:50
JDBC实现基本的CRUD示例
private static void insertTest() throws SQLException
{
String dbURL = "jdbc:mysql://localhost/test";
Connection con = DriverManager.getConnection(dbURL, "root", "123");
Statement st = con.createStatement();
st.execute("insert into user(ID,NAME) values(1, 'Zhang San')");
st.execute("insert into user(ID,NAME) values(2, 'Li Si')");
st.execute("insert into user(ID,NAME) values(3, 'Wang Wu')");
System.out.println("=====insert test=====");
showUser(st);
st.close();
con.close();
} private static void deleteTest() throws SQLException
{
String dbURL = "jdbc:mysql://localhost/test";
Connection con = DriverManager.getConnection(dbURL, "root", "123");
Statement st = con.createStatement();
st.execute("delete from user where ID=3");
System.out.println("=====delete test=====");
showUser(st);
st.close();
con.close();
} private static void updateTest() throws SQLException
{
String dbURL = "jdbc:mysql://localhost/test";
Connection con = DriverManager.getConnection(dbURL, "root", "123");
Statement st = con.createStatement();
st.executeUpdate("update user set NAME='TEST' where ID=2");
System.out.println("=====update test=====");
showUser(st);
st.close();
con.close();
} private static void showUser(Statement st) throws SQLException
{
ResultSet rs = st.executeQuery("select ID, NAME from user");
while(rs.next())
{
int id = rs.getInt("ID");
String name = rs.getString("NAME");
System.out.println("ID:" + id + "; NAME=" + name);
}
rs.close();
}
最新文章
- ajax 后台正常执行 错误类型却是404
- 为WebDriver 设置proxy(IE设置代理)
- nginx 配置https upstream 跳转失败
- [AngularJS] 使用AngularAMD动态加载Service
- C# 刷新页面浏览次数(点击量)+1
- PS 的参考线
- LICEcap 简洁易用的动画屏幕录制软件
- 装有Win7系统的电脑在局域网不能共享的解决方案
- Learn Objectvie-C on the Mac 2nd Edition 笔记
- HTTP协议和WEB应用
- css+div布局案例
- 用《内网穿山甲》把本地IIS中的站点共享到远程访问
- PHP获取远程文件的几种方式
- Visual studio 2017 未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage”包
- 学习使用Mendeley1
- VUE插件总结
- 20155324 2016-2017-2 《Java程序设计》第3周学习总结
- Android Day2
- Ajax进阶之原生js与跨域jsonp
- Linux中2>;&;1使用
热门文章
- 不使用Tomcat,手写简单的web服务
- Java——Iterate through a HashMap
- 重复代码Duplicated Code---要重构的信号
- bzoj 1696: [Usaco2007 Feb]Building A New Barn新牛舍 ——中位数排序
- spring-retry 重试机制
- python自动开发之第二十五天
- Linux内核基础--事件通知链(notifier chain)good【转】
- (八)hope
- 设计模式之笔记--建造者模式(Builder)
- (转)opencv 代替caffe.io.load_image