java连接mysql数据库jar包怎么导入
2个回答
2017-04-07 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
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();
}
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();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询