Cant connect to my SQL database

前端 未结 9 631
庸人自扰
庸人自扰 2021-01-04 18:24

So I\'m having an issue connecting to MySQL with Java. Heres my code:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException         


        
9条回答
  •  盖世英雄少女心
    2021-01-04 19:19

    Make sure that the database what you have mentioned in Host = "jdbc:mysql://localhost/worlddb"; i.e worlddb is correct or not. The name of the database here is CASE SENSITIVE! So, if you try to connect using a database name like "test2" instead of "Test2" , you will get the

    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'test2'
    

    Also try using port number too

    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/worlddb", "root", "password");
    

提交回复
热议问题