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();
}