* preparedstatement和statement的區別
* 關係:
* 1、都屬於執行sql語句的命令介面,都提供了一系列執行sql語句的方法
* 2、preparedstatement繼承了statement
* preparedstatement的好處:
* 1、不再使用+拼接sql語句,減少語法錯誤,語義性強
* 2、將模板sql(固定的部分)和引數部分進行了分離,提高維護性
* 3、有效的解決了sql注入問題
* 4、大大減少了編譯次數,效率較高
//使用statement實現登入
@test
public void teststatement() throws exception
set.close();
statement.close();
connection.close();
//}
//使用statement實現登入
@test
public void testpreparedstatement() throws exception
set.close();
statement.close();
connection.close();
}
JDBC 連線Mysql(筆記)
方法一 test public void testconnection1 throws exception 方法二 對方法一的迭代 在如下的程式中不出現第三方的api,使程式具有更好的可移植性 test public void testconnection2 throws exception 方式三...
mySQL筆記(十五) JDBC的使用2
jdbc的使用步驟1 載入驅動 類的載入時機 1 new 物件 2 載入子類 3 呼叫類中的靜態成員 4 通過反射 使用new物件的方式載入類的不足 1 屬於編譯期載入,如果編譯期間該類不存在,則直接編譯報錯,也就是依賴性太強 2 導致driver物件建立了兩遍,效率較低 採用反射的方式載入類 1 ...
mySQL筆記(十八) JDBC的使用5
1 事務 使用步驟 1 開啟新事務 取消隱式事務自動提交的功能 setautocommit false 2 編寫組成事務的一組sql語句 3 結束事務 commit 提交 rollback 回滾 細節 要求開啟事務的連線物件和獲取命令的連線物件必須是同乙個否則事務無效 2 批處理 案例 向admin...