JDBC
jdbc(Java DataBase Connectivity ):java 數(shù)據(jù)連接
maven 添加jar嫡纠,在pom.xml中dependencies添加扔枫,dependency節(jié)點(diǎn)
通過官網(wǎng):http://mvnrepository.com/家破,或者:https://search.maven.org/
官網(wǎng)下載jar在項(xiàng)目的web-abb-->WEB-INF下創(chuàng)建lib,右擊lib Add as? Library..
java 代碼連接數(shù)據(jù)庫(kù)
try{
注冊(cè)驅(qū)動(dòng):
Class.forName("com.mysql.jdbc.Driver");
//連接數(shù)據(jù)庫(kù)
Connection conn=DriverManager.getConnection("jdbc:mysql://location:3306/數(shù)據(jù)庫(kù)名","root","root");//返回Connection
//操作sql
String sql="sql語句";
Statement stm=conn.createStatement();
stm.executeUpdate();執(zhí)行增刪改返回 int 類型
stm.excuteQuery();執(zhí)行查詢盖溺,返回ResultSet
}catch (SQLException e) {
e.printStackTrace();
}