package com.itheima.first;
import java.sql.*;
public class Example01 {
public static void main(String[] args) throws SQLException {
Connection conn =null;
Statement stmt =null;
ResultSet rs =null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("加載驅動成功!");
String url="jdbc:mysql://localhost:3306/jdbc?useSSL=false&serverTimezone=UTC";
String username = "root";
String password = "246010";
conn = DriverManager.getConnection(url,username, password);
System.out.println("連接資料庫成功!url");
stmt = conn.createStatement();
String sql = "select * from tb_user";
rs = stmt.executeQuery(sql);
System.out.println("id | name | sex "
+ " | email | birthday ");
while (rs.next()) {
int id = rs.getInt("id");

String name = rs.getString("name");
String sex = rs.getString("sex");
String email = rs.getString("email");
Date birthday = rs.getDate("birthday");
System.out.println(id + " | " + name + " | "
+ sex + " | " + email + " | " + birthday);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(rs !=null){ rs.close(); }
if(stmt !=null){ stmt.close(); }
if(conn !=null){ conn.close(); }
}
}
}
uj5u.com熱心網友回復:
參考下這個https://blog.csdn.net/jadeshu/article/details/85345734
改下
uj5u.com熱心網友回復:
加載驅動成功的陳述句沒有列印出來,那就是驅動的問題,你引入了驅動包么,能看看是哪個版本的么?Class.forName("com.mysql.cj.jdbc.Driver");換成Class.forName("com.mysql.jdbc.Driver");試試?
uj5u.com熱心網友回復:
不行啊 我換了你們說的語言 還是報錯Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
正在加載類“com.mysql.jdbc.Driver”。這是不贊成的。新的驅動程式類是“com.mysql.cj.jdbc.driver”。驅動程式通過SPI自動注冊,通常不需要手動加載驅動程式類。
我都改過了 ,哎呀好生氣!
uj5u.com熱心網友回復:
可以試試這個:https://blog.csdn.net/weixin_43330884/article/details/102828455希望對你有幫助
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/80319.html
標籤:Eclipse
上一篇:JDBC
下一篇:Vue 路由跳轉至外界頁面
