运行java程序连接mysql数据库是出现如下结果怎么回事?
程序:importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException...
程序:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionDemo
{
public static final String DBDRIVER = "org.gjt.mm.mysql.Driver";
//数据库连接地址
public static final String DBURL = "jdbc:mysql://localhost:3306/mldn";
public static final String DBUSER = "MySQLserver";//数据库连接用户名
public static final String DBPASS = "manmanw68";//数据库连接密码
public static void main(String [] args){
Connection conn = null;
try
{
Class.forName(DBDRIVER);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
}
catch (SQLException e)
{
e.printStackTrace();
}
System.out.println(conn);
try
{
conn.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
运行结果:
C:\Users\伊郁\Desktop>java ConnectionDemo
java.sql.SQLException: Access denied for user 'MySQLserver'@'localhost' (using p
assword: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:934)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4104)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1299)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2338)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2
371)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at ConnectionDemo.main(ConnectionDemo.java:23)
null
Exception in thread "main" java.lang.NullPointerException
at ConnectionDemo.main(ConnectionDemo.java:32) 展开
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionDemo
{
public static final String DBDRIVER = "org.gjt.mm.mysql.Driver";
//数据库连接地址
public static final String DBURL = "jdbc:mysql://localhost:3306/mldn";
public static final String DBUSER = "MySQLserver";//数据库连接用户名
public static final String DBPASS = "manmanw68";//数据库连接密码
public static void main(String [] args){
Connection conn = null;
try
{
Class.forName(DBDRIVER);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
try
{
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
}
catch (SQLException e)
{
e.printStackTrace();
}
System.out.println(conn);
try
{
conn.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
运行结果:
C:\Users\伊郁\Desktop>java ConnectionDemo
java.sql.SQLException: Access denied for user 'MySQLserver'@'localhost' (using p
assword: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:934)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4104)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1299)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2338)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2
371)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at ConnectionDemo.main(ConnectionDemo.java:23)
null
Exception in thread "main" java.lang.NullPointerException
at ConnectionDemo.main(ConnectionDemo.java:32) 展开
展开全部
1没有导包 2没有数据库没有建好3密码错误
追问
这三个都是对的!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-10-14
展开全部
你的用户名有问题,再有你的driver 是自己封装的么,怎么不一样?
更多追问追答
追问
不是自己封装的!
追答
org.gjt.mm.mysql.Driver你在你的jar包中能找到相应的类么
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询