java.sql.SQLException上的Mysql连接失败:未选择数据库

时间:2015-10-19 11:50:37

标签: java mysql jdbc database-connection

在我的应用程序中,我通过具有此类URL的JDBC驱动程序创建连接

jdbc:mysql://localhost:3306/?connectionCollation=latin1_general_cs&user=user&password=password!

因此,url中未指定db。然后我的应用程序创建数据库,我试图通过使用:

强制我的连接使用此数据库
connection.setCatalog(databaseName);

但是语句执行失败了:

java.sql.SQLException: No database selected
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2531)
    at com.mysql.jdbc.ConnectionImpl.setCatalog(ConnectionImpl.java:4934)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:824)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:742)
    at org.fist.DB.connection.MySQLDatabaseConnection.executeSqlFile(MySQLDatabaseConnection.java:80)
    at org.fist.products.ssc.actions.InstallSSC.recreateDatabaseAndTables(InstallSSC.java:748)
    at org.fist.products.ssc.actions.InstallSSC.execute(InstallSSC.java:263)
    at com.mercury.mtf.core.AbstractAction.run(AbstractAction.java:51)
    at com.mercury.mtf.core.Unit.runUnitAction(Unit.java:277)
    at com.mercury.mtf.core.Unit.executeUnitAction(Unit.java:144)
    at com.mercury.mtf.core.Unit.run(Unit.java:99)
    at com.mercury.mtf.core.execution.DefaultUnitExecutor.call(DefaultUnitExecutor.java:24)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

0 个答案:

没有答案