增加数据
import util.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Add {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Connection connection = DBUtil.getConnection();
System.out.println(("创建连接成功"));
//3.写sql语句
String sql = " insert into tb_user(id,username,password) values('7548','zkx','pig')";
//4.获得statement对象
PreparedStatement statement = connection.prepareStatement(sql);
statement.executeUpdate();
DBUtil.closeAll(null, statement, connection);
}
}
删除数据
import util.DBUtil; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException;