javamysqljar
java連接mysql資料庫jar包導入:
1.將所有的jar包都是放到web工程lib目錄下,mysql-connector-java-x.x-bin.jar也是一樣,把該JAR包拷貝到lib目錄下即可
2用jdbc直接鏈接mysql代碼如下
public static void main(String[] args) throws SQLException {
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/day15", "root", "123456");
System.out.println(conn.getClass().getName());
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select id,name,password,email,birthday from users");
while (rs.next()) {
System.out.println("-------------------------");
System.out.println(rs.getObject("id"));
System.out.println(rs.getObject("name"));
System.out.println(rs.getObject("password"));
System.out.println(rs.getObject("email"));
System.out.println(rs.getObject("birthday"));
}
rs.close();
stmt.close();
conn.close();
}