Error :: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database '3306 table1
Posted by: xing chi
Date: October 04, 2010 03:51PM

This is the simple code that I was trying to execute in eclipse after creating a table by name table1 in MySql.

import java.sql.*;
public class EmployeeDemo {

public static void main(String[] args){

try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/3306 table1","root","sai");
System.out.println("Connected to db");
Statement st= con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM table1");
/*rs is of references*/
while(rs.next()) /*the rs pointer is pointing to the next ie it is pointing to the first row*/
{
System.out.print("Movie_Id: "+rs.getInt(1)); // rs.getInt("movie_id") is also valid
System.out.print("Title: " + rs.getString("title"));
System.out.println("Release_Date: "+ rs.getString(3));

}
}
catch(Exception e){

System.out.println("caught exception");
e.printStackTrace();
}
finally{

System.out.println("Done");
}

}
}



This is the error it shows.

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database '3306 table1'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.Util.getInstance(Util.java:384)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at EmployeeDemo.main(EmployeeDemo.java:9)
Done


Please let me know what could have gone wrong. Thanks in advance..

Options: ReplyQuote


Subject
Written By
Posted
Error :: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database '3306 table1
October 04, 2010 03:51PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.