当前位置: 技术问答>linux和unix
救命啊, linux 下java访问mysql……
来源: 互联网 发布时间:2014-11-20
本文导语: 使用mm.driver, 语句为 Class.forName("org.gjt.mm.mysql.Driver"); Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/vap", "vap", "vap"); Statement stmt = conn.createStatement(); rs = stmt.executeQuery("select * from users"); ...
使用mm.driver,
语句为
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/vap", "vap", "vap");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery("select * from users");
……
……
但是使用的时候, 报错:
java.sql.SqlException: cann't connection to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port, you are trying to connection to ? (java.net.unknown HostException)
如何解决??
语句为
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/vap", "vap", "vap");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery("select * from users");
……
……
但是使用的时候, 报错:
java.sql.SqlException: cann't connection to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port, you are trying to connection to ? (java.net.unknown HostException)
如何解决??
|
mysql启动了吗?监听程序启动了吗?
最好先关闭然后再启动一次
最好先关闭然后再启动一次
|
你的mysql可能没启动
java程序没错
java程序没错
|
netstat -a -n看看你的机器上3306有没有进程在监听?好像是java找不到对应的服务器服务进程