package PlasticWeaving.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBC使用ResultSet更新数据 {
public static void main(String[] args) {
String url="jdbc:mysql://localhost:3306/demo?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8";
String user="root";
String passwd="123456";
try {
//使用ResultSet更新数据
//
Class.forName("com.mysql.jdbc.Driver");
//
Connection con1 = DriverManager.getConnection(url,user,passwd);
//将Statement设置为可滑动,可更新
Statement state1=con1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
//
ResultSet set1 = state1.executeQuery("select * from goods;");
//1.将光标移至数据库最末行
set1.moveToInsertRow();
//2.更新结果集
set1.updateString("goodsid","123");
//3.向数据库中插入新的行
set1.insertRow();
//
state1.close();
con1.close();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
}