为了账号安全,请及时绑定邮箱和手机立即绑定

如何将我的远程 MySQL 数据库与 jdbc 连接?错误是什么意思?

如何将我的远程 MySQL 数据库与 jdbc 连接?错误是什么意思?

森林海 2022-09-28 16:19:55
显示错误:-Tue Apr 09 14:34:46 IST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.java.sql.SQLException: Access denied for user 'sql12287303'@'localhost' (using password: YES)我成功地在本地计算机中使用了数据库,但我无法连接到我的远程mysql服务器。public class JDBCDemo {    public static void main(String[] args) {        String TableName;        // TODO Auto-generated method stub        try{            String url="jdbc:mysql://localhost:3306/sql12287303";           //3306/db1?autoReconnect=true&useSSL=false";            String username="sql12287303";            String password="54hBDtsfPg";            Class.forName("com.mysql.jdbc.Driver").newInstance();            Connection con = DriverManager.getConnection(url, username, password);            System.out.println ("Database connection established");            System.out.println(con);            Statement smt = con.createStatement();            smt.execute("create database db1");            smt.execute("use db1");            smt.execute("create table flames(id Integer primary key,fname varchar(20),sname varchar(20)");            smt.execute("show tables");            ResultSet rs = smt.getResultSet();            while(rs.next()){                TableName = rs.getString(1);                System.out.println("Table Name:"+TableName);            }        }catch(Exception e){System.out.println(e);}     }}表名:火焰
查看完整描述

1 回答

?
蓝山帝景

TA贡献1843条经验 获得超7个赞

我想一个暗示是不够的。

此代码指示 JDBC 驱动程序连接到名为 上的数据库:sql12287303localhost

String url="jdbc:mysql://localhost:3306/sql12287303";

您报告的错误表明您实际上正在连接到 ,但其用户在运行该位置的数据库服务器上是未知的。localhost

如果要连接到远程数据库,则需要更改 URL:

String url="jdbc:mysql://sql12.freemysqlhosting.net:3306/sql12287303";


查看完整回答
反对 回复 2022-09-28
  • 1 回答
  • 0 关注
  • 77 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号