jdbc對mysql的增刪改查

2021-08-04 12:26:20 字數 1115 閱讀 5894

增  string sql= "insert into d_book values(?,?,?,?,?)";//預編譯

private  static dbutil db=new dbutil();

private static int addbook(bookmodel bookmodel1) throws exception

刪  string sql= "delete from d_book where id=? ";

private  static dbutil db=new dbutil();

private static int deletebook(int id) throws exception

改  string sql= "update d_book set bookname=?,bookprice=?,author=?,number=?";

private  static dbutil db=new dbutil();

private static int updatebook(bookmodel book1)throws exception

查  string sql="select * from d_book(where id= ?)";

private  static dbutil db=new dbutil();

private static void listbook() throws exception

boolean next()

throws sqlexception將游標從當前位置向前移一行。resultset 游標最初位於第一行之前;第一次呼叫 next 方法使第一行成為當前行;第二次呼叫使第二行成為當前行,依此類推。當呼叫 next 方法返回 false 時,游標位於最後一行的後面。任何要求當前行的 resultset 方法呼叫將導致丟擲 sqlexception。如果結果集的型別是type_forward_only,則其 jdbc 驅動程式實現對後續 next 呼叫是返回 false 還是丟擲 sqlexception 將由**商指定。 如果對當前行開啟了輸入流,則呼叫 next 方法將隱式關閉它。讀取新行時,將清除 resultset 物件的警告鏈。 

返回:如果新的當前行有效,則返回 true;如果不存在下一行,則返回 false 

JDBC 增刪改查

一 jdbc資料庫使用的七個基本步驟 獲取驅動 建立連線 編寫sql 獲取preparestatement 執行sql語句,並返回結果 處理結果集 關閉資源 根據這7個步驟寫 public class testuser else catch exception e 7.關閉資源 finallycat...

JDBC 實現增刪改查

public class notedaoimpl implements notedao catch exception e finally 修改操作 public void update note note throws exception catch exception e finally 刪除操...

JDBC實現增刪改查

對資料庫進行增刪改操作的步驟 1.通過connection物件建立statement,statement的功能是向資料庫傳送sql語句。2.通過呼叫int executeupdate string sql 它可以傳送dml和ddl 例項 class.forname com.mysql.jdbc.dr...