public class DButils {
private static Connection connection = null ;
private static String drivname ="com.mysql.jdbc.Driver";
private static String username = "root";
private static String password = "123123";
private static String url= "jdbc:mysql://localhost:3306:/sys";
public static Connection getConnection() {
if (connection == null) {
try {
Class.forName(drivname);
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
return connection;
}
}
jdbc:mysql://localhost:3306:/sys
多了一个冒号
换成
private static String url= "jdbc:mysql://localhost:3306/sys";
url: jdbc:mysql://localhost:3306/book
所以是/sys之前多了冒号
private static String url= "jdbc:mysql://localhost:3306:/sys";
NumberFormatException数字转换异常, For input string: "3306:"输入字符串3306:, :冒号肯定转不了数字
参考格式如下
jdbc:oracle:thin:@localhost:1993:dbnms
jdbc:mysql://ip:3306/database
jdbc:clickhouse://ip:9000
jdbc:hive2://ip:10000/default
jdbc:postgresql://ip:5432/database