NetBeans中未显示java.sql.connection [英] java.sql.connection not showing up in netbeans
问题描述
public Connection MySqlConnection(){
Connection conn=null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/project","root","root");
return conn;
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"MySql connection failed");
return null;
}
}
我的Netbeans没有为我提供导入java.sql.connection
的选项.我已经在库中添加了lib\mysql-connector-java-8.0.18.jar
.此外,我还能够在Netbeans的服务"选项卡中查看我的所有数据库.我正在做一个Swing项目.谢谢!
My Netbeans is not giving me options to import the java.sql.connection
. I have added the lib\mysql-connector-java-8.0.18.jar
in my library. Additionally, I am also able to see all my databases in the services tab in Netbeans. I am working on a Swing project. Thank you!
推荐答案
将Connector/J API的版本从5.1更改为8.0:
Changes to the Connector/J API going from version 5.1 to 8.0:
名字
在MySQL Connector/J中实现java.sql.Driver的类的类具有
从com.mysql.jdbc.Driver
更改为com.mysql.cj.jdbc.Driver
.这
旧的类名已被弃用.
The name
of the class that implements java.sql.Driver in MySQL Connector/J has
changed from com.mysql.jdbc.Driver
to com.mysql.cj.jdbc.Driver
. The
old class name has been deprecated.
来源: https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-api-changes.html
这篇关于NetBeans中未显示java.sql.connection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!