jdbc主要由三個步驟組成
1.匯入jar包
2.載入驅動
3.連線資料庫
public class databaseutil
static catch (classnotfoundexception e)
}public static connection getconnection() catch (sqlexception e)
} } catch (sqlexception e)
return connection;
}public static void closeconnection() catch (sqlexception e) }}
}往資料庫中新增資料
public class comdao
public int add(teacher teacher) catch (sqlexception e) finally catch (sqlexception e)
} }return result;
}通過老師id來修改資料庫
public int update(teacher teacher) catch (sqlexception e) finally catch (sqlexception e)
} }return result;
}根據老師id來查詢老師具體資訊
public int update(teacher teacher) catch (sqlexception e) finally catch (sqlexception e)
} }return result;
}
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...
JDBC實現增刪改查
首先建立起資料庫連線 1 載入驅動 class.forname com.mysql.jdbc.driver 2 獲取與資料庫的連線 string username root string password 123456 string url jdbc mysql localhost 3306 jdb...