Cant connect to my SQL database

前端 未结 9 558
庸人自扰
庸人自扰 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:16

    Are you sure that the DB server is not case sensitive? I mean maybe on the DB server the DB name is WorldDb and you are trying to connect to it by using worlddb (all low lecters).. Try to use the same name or to configure MySQL to be case insensitive

    0 讨论(0)
  • 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");
    
    0 讨论(0)
  • 2021-01-04 19:23

    Write

    "jdbc:mysql://localhost:3306/worlddb"
    

    instead of

    "jdbc:mysql://localhost/worlddb"
    
    0 讨论(0)
提交回复
热议问题