如何規範你的Git commit?
阿新 • • 發佈:2021-10-03
SMBMS
資料庫:
專案如何搭建?
考慮使用不使用Maven? 使用的話要依賴,不使用要導jar包
專案搭建準備工作
-
搭建一個maven web專案
-
配置tomcat
-
測試專案是否能夠跑起來
-
匯入專案中會遇到的jar包;
jsp、Servlet、mysql驅動、jstl、stand.......
-
建立專案包結構
-
編寫實體類;
ORM對映:表-類對映
-
編寫基礎公共類
-
資料庫配置檔案
driver=com.mysql.jdbc.Driver
url="jdbc:mysql://localhost:3306/smbms?useUnicode=true&characterEncoding=utf8&useSSL=true"
username=root
password=123456-
編寫資料庫的公共類
//靜態程式碼塊,類載入的時候就初始化了
static {
Properties properties = new Properties();
//通過類載入器讀取對應的資源
InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
try {
properties.load(is);
} catch (IOException e) {
e.printStackTrace();
}
driver = properties.getProperty("driver");
url = properties.getProperty("url");
username = properties.getProperty("username");
password = properties.getProperty("password");
}
//獲取資料庫的連線
public static Connection getConnection(){
Connection connection = null;
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
//編寫查詢公共類
public static ResultSet exexute(Connection connection,String sql,Object[] params,ResultSet resultSet,PreparedStatement preparedStatement ) throws SQLException {
//預編譯的sql,在後面直接執行就可以了
preparedStatement = connection.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
//setObject,佔位符從1開始,但是我們的陣列是從0開始!
preparedStatement.setObject(i + 1, params[i]);
}
resultSet = preparedStatement.executeQuery(sql);
return resultSet;
}
//編寫增刪改公共方法
public static int exexute(Connection connection,String sql,Object[] params,PreparedStatement preparedStatement ) throws SQLException {
preparedStatement = connection.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
//setObject,佔位符從1開始,但是我們的陣列是從0開始!
preparedStatement.setObject(i+1,params[i]);
}
int updateRows = preparedStatement.executeUpdate(sql);
return updateRows;
}
//釋放資源
public static boolean closeResource(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet){
-
-