连接到 phpmyadmin 时出错
Posted
技术标签:
【中文标题】连接到 phpmyadmin 时出错【英文标题】:Error connecting to phpmyadmin 【发布时间】:2018-09-06 15:10:56 【问题描述】:所以我正在使用 netbeans,我有基本代码可以在 phpmyadmin 中连接到我的数据库,但它给了我错误,我不知道为什么。
public Connection getConnection()
Connection con;
try
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "");
return con;
catch(Exception e)
e.printStackTrace();
return null;
我确实在库中有 mysql-connector-java-5.1.46-bin
文件,但它仍然给我这个:
java.sql.SQLException: No suitable driver found for
jdbc:mysql//localhost/test
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247
at bdaysms.Main.getConnection(Main.java:20)
at bdaysms.Main.getContactsList(Main.java:31)
at bdaysms.Main.Show_Users(Main.java:53)
at bdaysms.Main.<init>(Main.java:12)
at bdaysms.Main$4.run(Main.java:272)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
java.lang.NullPointerException
at bdaysms.Main.getContactsList(Main.java:38)
at bdaysms.Main.Show_Users(Main.java:53)
at bdaysms.Main.<init>(Main.java:12)
at bdaysms.Main$4.run(Main.java:272)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
我的代码有问题还是我缺少要连接的东西?
【问题讨论】:
【参考方案1】:也提供端口
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
mysql默认端口3306
【讨论】:
我刚刚从 xampp 检查了我的端口,但即便如此,同样的问题也会发生。以上是关于连接到 phpmyadmin 时出错的主要内容,如果未能解决你的问题,请参考以下文章
将 Android 应用程序连接到外部数据库 (phpmyadmin)
无法从 Ubuntu 服务器上的外部站点连接到 phpMyAdmin