package day01.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;
import org.junit.*;
public class Shanchu03 {
@Test
public void test01() {
Connection conn=null;
PreparedStatement pstm=null;
Scanner sca=new Scanner(System.in);
try {
//1.加载驱动
Class.forName("com.mysql.jdbc.Driver");
//2.创建连接
String url="jdbc:mysql://localhost:3306/study";
conn=DriverManager.getConnection(url, "root", "root");
//3.执行sql语句
String sql="delete from us where book_name='lalala'";
pstm=conn.prepareStatement(sql);
pstm.executeUpdate();
System.out.println("删除数据成功!!");
}catch(Exception e) {
e.printStackTrace();
}
finally {
//4.关闭资源
if(pstm!=null) {try{pstm.close();}catch(Exception e) {}}
if(conn!=null) {try{conn.close();}catch(Exception e) {}}
}
}
}
不知道 写神魔好 就这个了 本人菜鸟 路过的大佬勿喷 谢谢!!