Reputation: 21893
I amusing cloudSQL and I keep getting this error "No database selected" when I deploy my website into production.
The dump that I uploaded to cloudsql has the line "USE mydb" i have to my a db call for "use mydb" every any query works.
Anyone know why? or how to fix it
java.sql.SQLException: No database selected
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2739)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2149)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2313)
Upvotes: 0
Views: 637
Reputation: 9721
Either set the database as part of the jdbc connection string, like jdbc:google:mysql://your-project-id:your-instance-name/YOUR_DATABASE_NAME
, or switch to it with Connection.setCatalog(). As mentioned on the MySQL Docs you cannot use USE db
syntax with MySQL via JDBC.
Upvotes: 2