[问题]MYSQL 连接数据库问题 请指教

数据库服务和管理,MySQL/PostgreSQL/Oracle/Sybase 等
回复
godencrystal
帖子: 86
注册时间: 2007-07-17 21:48
来自: SJTU
送出感谢: 0
接收感谢: 0

[问题]MYSQL 连接数据库问题 请指教

#1

帖子 godencrystal » 2007-09-04 0:26

MYSQL已经装好了, 并建立了名为 storemanagement的database , 而且也添加 了 驱动 但是运行下面代码还是说database名出错,请问该如何解决,谢谢!
package becker;

import java.sql.*;

public class Database {
public static void main(String argv[]) {
Connection con = null;
try {
// here is the JDBC URL for this database
String url ="jdbc:mysql://localhost:3306/storemanagement ?"+"user=root&password=backer&useUnicode=true&characterEncoding=gbk";
// more on what the Statement and ResultSet classes do later
Statement stmt;
ResultSet rs;
// either pass this as a property, i.e.
// -Djdbc.drivers=org.gjt.mm.mysql.Driver
// or load it here as we are doing in this example
try {
Class.forName("com.mysql.jdbc.Driver");


} catch (Exception e) {
// TODO: handle exception
System.out.println("e");
}

// here is where the connection is made
con = DriverManager.getConnection(url);
}
catch( SQLException e ) {
e.printStackTrace( );
}
finally {
if( con != null ) {
try {
System.out.println("Collection succeeded!");

con.close( ); }
catch( Exception e ) { }
}
}
}
}


出错信息是:(确定database name 名没有错)
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Incorrect database name 'storemanagement '
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2748)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at becker.Database.main(Database.java:27)
MMLXX
回复

回到 “数据库管理”