为什么我的SQL连接卡住了

为什么我的SQL连接卡住了

本文介绍了当我使用DriverManager.getConnection时,为什么我的SQL连接卡住了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Java代码如下所示,并且我的机器上运行着一个MySQL数据库.

I have Java code that looks as follows and a MySQL database running on my machine.

System.out.println("Loading JDBC");
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("JDBC loaded");
System.out.println("Establishing connection");
myConnection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:1186/dbname","username","password");
System.out.println("Connection established");

但是,我得到的输出如下:

However, the output I get is the following:

Loading JDBC
JDBC loaded
Establishing connection

然后什么都没有?它不会报告连接错误,因此必须连接.这是怎么回事?为什么不转到下一行代码?

and then nothing? it doesn't report an error connecting, so it must be connected.What's going on? why isn't it moving to the next line of code?

我将不胜感激

推荐答案

几点:

  1. 数据库的名称是什么?如果您尝试运行上面显示的代码,则数据库名称必须为"dbname",用户名必须为"username",密码必须为"password".

  1. What is the name of database? If you are trying to run the code shown above, than database name must be "dbname", username must be "username" and password must be "password".

您的MySQL正在监听端口1186吗?我只是想知道,通常在安装时,默认端口设置为3306.

Is your MySQL listening to port 1186? I am just wondering as generally at the time of installation default port is set to 3306.

如果要遵循将MySQL与JDBC连接所涉及的步骤,可以查看本教程的 JDBC步骤.

If you want to follow steps involved in connecting MySQL with JDBC, you can take a look to this tutorial for JDBC Steps.

Jwalant

这篇关于当我使用DriverManager.getConnection时,为什么我的SQL连接卡住了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-21 03:14