JDBC连接MySQL的问题.

lulu168 2005-12-30 09:26:17
开发环境:
WINXP SP2 +JBX+MYSQL5.0

原马:

package struts;
import java.sql.*;
import java.util.*;
import java.io.*;

public class ConnTest {
private static String URL;
private static String DatabaseName;
private static String user;
private static String password;
/* static{
Locale locale = Locale.getDefault();

ResourceBundle bundle = ResourceBundle.getBundle(db.properties",locale);
URL=bundle.getString("URL");
DatabaseName=bundle.getString("DatabaseName");
user=bundle.getString("user");
password=bundle.getString("password");
}*/

public ConnTest() {



}
public static void main(String[] args){
try{
Class.forName("org.gjt.mm.mysql.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/Struts","root","");
/*Statement stmt=con.createStatement();
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
System.out.println(rs.getString("name"));
}*/
}catch(Exception e){

System.out.print("Exception");
e.printStackTrace();
}
}

}

控制台输出:


java.sql.SQLException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.lang.NumberFormatException)

MYSQL已经运行了, 在控制面扳了可见.
...全文
576 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lulu168 2006-01-02
  • 打赏
  • 举报
回复
是MYSQL安装错误,已经解决了,谢谢大家.

并不时端口被占用.
tondayong1981 2006-01-01
  • 打赏
  • 举报
回复
以前用过一次,没有深究,不过我记得是在安装的时候安装在默认位置,好了之后再复制到用户想放的位置。你试试
网络精灵 2005-12-31
  • 打赏
  • 举报
回复
mysql-front只显示有限的记录,多了,它就不显示了,在设置里有吗?在哪里?执行:net start mysql
提示:MYSQL服务已启动成功
说明端口没被占用。
yeshucheng 2005-12-31
  • 打赏
  • 举报
回复
应该是你的当前端口被别的程序占用了
建议你换个数据库试下看,如果别的行表示就是我说的问题(可以建议使用postgresql)
全粘架构师 2005-12-31
  • 打赏
  • 举报
回复
装个MYSQLCC看看能连数据库到吗
zag 2005-12-31
  • 打赏
  • 举报
回复
楼主安装的MySQL是否更改了连接端口号,按错误提示的意思应该是这样的,还有就是,你的MySQL运行起来了没有。
如果改了端口号,则需把
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/Struts","root","");
改为:
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:[端口号]/Struts","root","");
试试。
storm56 2005-12-31
  • 打赏
  • 举报
回复
你先用客户端工具连一下是否成功?
zhkchi 2005-12-30
  • 打赏
  • 举报
回复
应该是启动有问题了
你换EMS连接试试就知道了
xiongbing528 2005-12-30
  • 打赏
  • 举报
回复
楼主。你可以去下个mysql-front来玩完。。比你在DOS下玩MYSQL舒服多了。。。
lulu168 2005-12-30
  • 打赏
  • 举报
回复
用命令执行:

MYSQL -U ROOT -P <C:\DB.SQL

提示:

ERROR2003<HY000>:Can not connnect to MySQL server on 'localhost'<10061>


执行:net start mysql
提示:MYSQL服务已启动成功


是不是MYSQL安装不对?


67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧