java数据库连接出错,怎么办?
publicloginsure(Strings,Stringa)throwsSQLException,ClassNotFoundException{StringDBDRI...
public loginsure(String s,String a) throws SQLException, ClassNotFoundException
{
String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
Class.forName(DBDRIVER);
//连接到指定数据库的URL
String URL = "jdbc:mysql://localhost:3306;DatabaseName=rlzygl";
Connection conn = DriverManager.getConnection(URL,"root","mysqladmin");
Statement stmt=conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from alluser");
while (rs.next())
{
name=rs.getString("username").trim();
错误提示内容如下:
: No suitable driver found for jdbc:mysql://localhost:3306;DatabaseName=rlzygl
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at pc.loginsure.<init>(loginsure.java:17)
at pc.login.actionPerformed(login.java:57)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source) 展开
{
String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
Class.forName(DBDRIVER);
//连接到指定数据库的URL
String URL = "jdbc:mysql://localhost:3306;DatabaseName=rlzygl";
Connection conn = DriverManager.getConnection(URL,"root","mysqladmin");
Statement stmt=conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from alluser");
while (rs.next())
{
name=rs.getString("username").trim();
错误提示内容如下:
: No suitable driver found for jdbc:mysql://localhost:3306;DatabaseName=rlzygl
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at pc.loginsure.<init>(loginsure.java:17)
at pc.login.actionPerformed(login.java:57)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source) 展开
4个回答
展开全部
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/aigo?user=root&password=root&useUnicode=true&characterEncoding=gb2312" ;
这个是我的代码 希望对你有用 另外也得看看你下载的MYSQL CONNECTION
String url ="jdbc:mysql://localhost:3306/aigo?user=root&password=root&useUnicode=true&characterEncoding=gb2312" ;
这个是我的代码 希望对你有用 另外也得看看你下载的MYSQL CONNECTION
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
这个不对吧 。。
报错是驱动不对。。。你用的是mysql的驱动?
这个不对吧 。。
报错是驱动不对。。。你用的是mysql的驱动?
更多追问追答
追问
是,要怎么改,但是在另一个项目里也是这么写的能用的啊
追答
com.mysql.jdbc.Driver
。。我用的是mysql 5.5 的驱动,你看着你对应的版本。。应该有对应的语句的。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
jdbc驱动包放进来了么?
错误提示是jdbc驱动不正确。
错误提示是jdbc驱动不正确。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询