Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql wampserver 2.4的JDBC连接问题_Mysql_Wampserver - Fatal编程技术网

Mysql wampserver 2.4的JDBC连接问题

Mysql wampserver 2.4的JDBC连接问题,mysql,wampserver,Mysql,Wampserver,谢谢你给我宝贵的时间。 我正在尝试使用WampServer 2.4在应用程序和数据库之间建立连接。我的配置文件包含与默认MySQL特权帐户相对应的设置(root,无密码)。我的MySQL服务器正在使用此默认值运行, 我正在使用此代码建立连接 import java.lang.ClassNotFoundException; import java.sql.Connection; import java.sql.Statement; import java.sql.DriverManager; im

谢谢你给我宝贵的时间。 我正在尝试使用WampServer 2.4在应用程序和数据库之间建立连接。我的配置文件包含与默认MySQL特权帐户相对应的设置(root,无密码)。我的MySQL服务器正在使用此默认值运行, 我正在使用此代码建立连接

import java.lang.ClassNotFoundException;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.SQLException;


public class implementation {

    public static void main(String[]arg)
    {

        Connection connection = null;
        Statement statement = null;

        try
        {
            System.out.println("conneting to Database...");
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost:80/db","root","");
            System.out.println("Connection Successful");

        }
        catch(ClassNotFoundException error)
        {
            System.out.println("Error:" + error.getMessage()); 
        }

        catch(SQLException error)
        {
            System.out.println("Error:" + error.getMessage());
        }
        finally
        {
            if (connection != null) 
                try {
                    connection.close();
                    }
            catch(SQLException ignore)
            {

            }

            if (statement != null) 
                try {
                    statement.close();
                    }

            catch(SQLException ignore)
            {

            }
        }
    }

}
当我运行此代码时,它不会将我连接到数据库。因此,我尝试获取正确的端口,我检查了phpinfo(),发现这个主机名:端口|本地主机:0

所以我把一行代码改成了这个

connection = DriverManager.getConnection("jdbc:mysql://localhost:0/db","root","");
当我运行这条新线时,出现了这个错误

正在连接到数据库

错误:通信链路故障

上次发送到服务器的数据包是0毫秒前的。

请给我你的指导来解决这个问题。
谢谢

这可能是您的错误:

 connection = DriverManager.getConnection("jdbc:mysql://localhost:80/db","root","");
此命令中使用的端口80是Apache侦听的端口。默认情况下,MySQL侦听端口3306

如果您没有更改,那么您可能根本不需要在这个CMM上添加:xxx端口号

所以试试看

 connection = DriverManager.getConnection("jdbc:mysql://localhost/db","root","");
看看这对你有用吗

否则尝试

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

首先检查JDBC使用的端口号和其他应用程序是否使用的端口号

检查您的端口号
80
是否被其他应用程序使用,如果是,则必须终止端口号80,或者必须重新配置JDBC服务器以在其他端口号上运行

查看以下链接:

您的MySQL服务器可能正在侦听默认端口,因此不需要在连接字符串中指定端口。只需使用
jdbc:mysql://localhost/db
thnx@rsanschez,它成功了:)谢谢你宝贵的时间,你的回答真的很有帮助,你解决了我的问题。。。thanx很多配偶:)