Cant connect to my SQL database

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

    There is a difference between name of connection and name of Database,try world, test or sakila from schemas in the picture.

    0 讨论(0)
  • 2021-01-04 19:05
    connection = DriverManager.getConnection("jdbc:mysql://localhost/worlddb?" +"user=root&password=password");
    

    Try this, I have a connection to mysql db with same connection, you just add ? after the name of the db.

    0 讨论(0)
  • 2021-01-04 19:07

    Try this it's hopeful for you:

    Connection con = null;
    Class.forName("com.mysql.jdbc.Driver");
    con =DriverManager.getConnection("jdbc:mysql://localhost/worlddb","root","password"); 
    
    0 讨论(0)
  • 2021-01-04 19:12

    Charaf jra was right i had the same issue.
    your schema(schema = Database) is listed as Host = "jdbc:mysql://localhost/worlddb"; If you look at the schemas in the pic you posted https://postimg.cc/image/593stjvjx/
    the schema(Database) is world.

    0 讨论(0)
  • 2021-01-04 19:15

    In the above code, port number is missing.

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

    default port number of mysql is 3306

    0 讨论(0)
  • 2021-01-04 19:15

    Take care to not have white spaces and use jdbc:mysql://localhost:3306/dbname

    0 讨论(0)
提交回复
热议问题