Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Eclipse gives me a lot of errors when i try to connect to my database. Here is the code:

public static void main(String[] args) throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(
    "jdbc:mysql://127.0.0.1:3306/Turniir", "root", "root");
    System.out.println("Connected to MySQL"); 
con.close(); 
}

First it says Unknown database 'turniir'. In mysql workbench, there is a connection 127.0.0.1:3306 , it uses a schema , in workbench i can insert rows and i get a connection tho. The user and pw should be root , atleast i use them to log in. But there are like 30 errors ...

Also in eclipse , i have mysql connector 5.1.27 under referenced libraries and eclipse does not show any red flags when i examine my code , only when i run.

I think the problem is in jdbc:mysql://127.0.0.1:3306/Turniir", "root", "root" this code, either i have somehow changed server or i don't know what password or username is for server or i don't know the right server ip/name ...

Database : http://www.upload.ee/image/3724759/mysqldb.png

Connection thingy : http://www.upload.ee/image/3724938/cra0.png

These are the errors :

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:          Unknown database 'turniir'
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:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)
at    com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2493)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2526)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2311)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
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 Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Program.main(Program.java:12)
share|improve this question
    
attach stacktrace to question –  Mark Nov 24 '13 at 13:47
    
What are the errors ? –  kocko Nov 24 '13 at 13:47
    
Does it print out the System.out.println("Connected to MySQL"); in the console? –  peeskillet Nov 24 '13 at 14:05
    
It does not print out connected to MySQL. I still think the problem is on first line : Unknown database : turniir , but i have it ... –  user3027316 Nov 24 '13 at 14:07
    
AFAIR By default MySQL did NOT allow remote/TCP connections using root –  Germann Arlington Nov 24 '13 at 14:20

2 Answers 2

You said Turiir is not the database name. That's why you're getting the error

"jdbc:mysql://127.0.0.1:3306/Turniir", "root", "root");

   // This need to be database ^^^^

                      // this username ^^^^

                              // this password  ^^^^

If you run mysql and type show databases and turniir does't show up, then it's not a database. Replace the above code with a valid datadase.

share|improve this answer

maybe the case sensitive of the ‘turniir’,the error msg shows ‘Turniir’

share|improve this answer
    
No , returns the same error. –  user3027316 Nov 24 '13 at 15:14
    
In mysql, type ‘show databases’,what is the output? –  dandy1992 Nov 24 '13 at 15:20
    
7 different names : information_schema mysql performance_schema projtournament sakila test world Why are they there, i have never even seen some of those names ... ? –  user3027316 Nov 24 '13 at 15:36
    
aha, they are there after you install mysql,you should try type 'create database turniir',and the code will run ok ~,you will find it~ –  dandy1992 Nov 25 '13 at 2:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.