package step1
;
import java
.sql
.*
;
public class UpdatePass {
public static void updateDB() {
try {
Class
.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ce
) {
System
.out
.println("SQLException:" + ce
.getMessage());
}
Connection con
=null
;
Statement stat
=null
;
try{
con
= DriverManager
.getConnection("jdbc:mysql://127.0.0.1:3306/tsgc?useUnicode=true&characterEncoding=utf-8", "root", "123123");
stat
= con
.createStatement();
stat
.executeUpdate("update employee set password='hello' where sex='女'");
}
catch (SQLException e
) {
System
.out
.println("SQLException1:" + e
.getMessage());
}
finally {
try {
if (stat
!= null
) {
stat
.close();
}
} catch (SQLException e
) {
e
.printStackTrace();
}
try {
if (con
!= null
) {
con
.close();
}
} catch (SQLException e
) {
e
.printStackTrace();
}
}
}
}
package step1
;
import java
.sql
.*
;
public class QueryPass {
public static void queryDB() {
try {
Class
.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ce
) {
System
.out
.println("SQLException:" + ce
.getMessage());
}
Connection con
= null
;
Statement stat
= null
;
ResultSet rs
= null
;
try{
con
= DriverManager
.getConnection("jdbc:mysql://127.0.0.1:3306/tsgc?useUnicode=true&characterEncoding=utf-8", "root", "123123");
stat
= con
.createStatement();
rs
= stat
.executeQuery("select * from employee");
while (rs
.next()) {
System
.out
.println("no:" + rs
.getString("no") + "\t" + "name:" + rs
.getString("name") + "\t" + "password:" + rs
.getString("password") + "\t" + "sex:"+ rs
.getString("sex") + "\t" + "salary" + rs
.getFloat("salary"));
}
}
catch (SQLException e
) {
System
.out
.println("SQLException1:" + e
.getMessage());
}
finally {
try {
if (stat
!= null
) {
stat
.close();
}
} catch (SQLException e
) {
e
.printStackTrace();
}
try {
if (con
!= null
) {
con
.close();
}
} catch (SQLException e
) {
e
.printStackTrace();
}
}
}
}
李响Superb
认证博客专家
机器学习
TensorFlow
图像处理
成为一名优秀的算法工程师⬆️ ,目前还在读软件工程,AI攻防、算法和深度学习方向,微博同名❤️ :李响Superb,(记得关注,有问题微博私信!)我们一起努力呀!
转载请注明原文地址: https://mac.8miu.com/read-512790.html