package com
.fy
;
import java
.sql
.Connection
;
import java
.sql
.DriverManager
;
import java
.sql
.Statement
;
public class Test3 {
public static void main(String
[] args
) throws Exception
{
Test3
.update(8, "小乔");
}
private static void update(int id
, String name
) throws Exception
{
Class
.forName("com.mysql.jdbc.Driver");
Connection conn
= DriverManager
.getConnection("jdbc:mysql:///day0901", "root", "1234");
String sql
= "update tb1 set name = '"+name
+"' where id = " +id
;
Statement s
= conn
.createStatement();
int row
= s
.executeUpdate(sql
);
if(row
!= 0) {
System
.out
.println("修改成功");
}else{
System
.out
.println("修改失败");
}
conn
.close();
s
.close();
}
}
表中原始数据
执行java代码
修改后的数据
转载请注明原文地址:https://tech.qufami.com/read-1180.html