Statement
- Statement用於執行sql語句
- DDL --> 對庫與表的增刪改查操作
DML --> 對數據的增刪改操作
DQL --> 對數據的查詢操作
@Test
public void testDDL() throws Exception {
//添加jar包
//加載驅動
//Class.forName("com.mysql.cj.jdbc.Driver");
//如果連接的是本機mysql並且端口試默認的3306可以簡化書寫
//String url = "jdbc:mysql://localhost:3306/db1";
String url = "jdbc:mysql:///db1";
String user = "xxxx";
String pwd = "ooooo";
Connection conn = DriverManager.getConnection(url, user, pwd);
//定義sql語句
String sql = "drop database db2";
//獲取執行sql的對象 statement Statement statement = conn.createStatement();
//執行sql
int update = statement.executeUpdate(sql);//執行完ddl 返回可能為0
//處理結果
/*if(update == 0){
System.out.println("修改失敗~");
}else { System.out.println("修改成功~");
}*/ System.out.println(update);
//釋放資源
statement.close();
conn.close();
}
@Test
public void testDDL() throws Exception {
//添加jar包
//加載驅動
//Class.forName("com.mysql.cj.jdbc.Driver");
//如果連接的是本機mysql並且端口試默認的3306可以簡化書寫
//String url = "jdbc:mysql://localhost:3306/db1";
String url = "jdbc:mysql:///db1";
String user = "eddieliao";
String pwd = "jtjyly611024";
Connection conn = DriverManager.getConnection(url, user, pwd);
//定義sql語句
String sql = "drop database db2";
//獲取執行sql的對象 statement Statement statement = conn.createStatement();
//執行sql
int update = statement.executeUpdate(sql);//執行完ddl 返回可能為0
//處理結果
/*if(update == 0){
System.out.println("修改失敗~");
}else { System.out.println("修改成功~");
}*/ System.out.println(update);
//釋放資源
statement.close();
conn.close();
}