无法连接到我的SQL数据库 [英] Cant connect to my SQL database

查看:128
本文介绍了无法连接到我的SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在使用Java连接MySQL时遇到了问题。
继承我的代码:

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;


public class DBAccess {
    private String Host;
    private String User;
    private String Password;

    public DBAccess() throws ClassNotFoundException, SQLException{
    Class.forName("com.mysql.jdbc.Driver");
    Password = "password";
    Host = "jdbc:mysql://localhost/worlddb";
    User = "root";
    @SuppressWarnings("unused")
    Connection connect = DriverManager.getConnection(Host,User,Password);
        System.out.println("Connected!"); 
    }
    public void RetreiveData(){

    }
    public void ChangeData(){
    }

}

我得到的错误是线程main中的异常

The error that I'm getting is Exception in thread "main"

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

http://postimg.org/image/593stjvjx/
在mySQL工作台中,我的连接名称是worlddb
主机名是Liquidus(这是本地主机)

http://postimg.org/image/593stjvjx/ in mySQL workbench, my connection name is "worlddb" hostname is Liquidus(which is the localhost)


  • socket是MySQL

  • 端口:3306

为什么会这样?

推荐答案

连接名称和数据库名称之间存在差异,请尝试世界测试 sakila 来自图片中的模式。

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

这篇关于无法连接到我的SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆