sql增删改查jdbc

package com.song.testjdbc;

import java.sql.*;

public class test2 {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
//连接数据库
String url = "jdbc:mysql://localhost:3306/java_test?useUnicode=true&characterEncoding=utf8&useSSL=true";
String name = "root";
String pwd = "123456";
connection = DriverManager.getConnection(url, name, pwd);
//connection代表数据库

String sql = "DELETE from tb_user Where userid=1";
//执行sql对象
statement = connection.createStatement();
int i = statement.executeUpdate(sql);
if (i>0){
System.out.println("插入成功");
}


statement.close();
connection.close();
}

}
posted @ 2022-06-07 16:57  小松2739  阅读(38)  评论(0)    收藏  举报