package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Demo02jdbc {
public static void main(String[] args) {
Connection conn =null;
Statement stmt =null;
try {
Class.forName("com.mysql.jdbc.Driver");
String sql = "update stu_account set balance = 1500 where id = 3";
conn = DriverManager.getConnection("jdbc:mysql://服务器:端口/数据库名字", "账号", "密码");
stmt = conn.createStatement();
int count = stmt.executeUpdate(sql);
System.out.println(count);
if(count > 0){
System.out.println("执行成功");
}else{
System.out.println("执行失败");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally{
if(stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
最后
以上就是美满小鸽子最近收集整理的关于jdbc mysql update语句_java常用知识:jdbc练习update语句的全部内容,更多相关jdbc内容请搜索靠谱客的其他文章。
发表评论 取消回复