Jsp连接MySQL问题

wisdom5034201 2006-04-03 07:42:37
小弟出学Jsp ,在连接MySQL时遇到麻烦请帮忙看看

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
out.println("Success loading Mysql Driver!");
}
catch (Exception E) {
out.println("Unable to load driver.");
}

try {
Connection C = DriverManager.getConnection("jdbc:mysql://localhost/news?user=rg&password=rg&useUnicode=true&characterEncoding=8859_1");
Statement s=C.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=s.executeQuery("select * from master");
out.print("Success connect Mysql server!");
out.println("<table border=1>");
int i=1;
for (i=10;i<20;i++)
{
if (rs.absolute(i))
{
out.println("<tr><td>");
out.println(rs.getString(1));
out.println("</td>");
out.println("<td>");
out.print(rs.getString(2));
out.println("</td>");
out.println("<td>");
}
else
{
break;
}

}
out.println("</table>");
rs.close();
s.close();
C.close();
}
catch (SQLException E) {
out.println("SQLException: " + E.getMessage());
out.println("SQLState: " + E.getSQLState());
out.println("VendorError: " + E.getErrorCode());
}

%>


连接结果是
Success loading Mysql Driver! SQLException: Communication failure during handshake. Is there a server running on localhost:3306? SQLState: null VendorError: 0
我用MySQL-front 是可以连上的
...全文
294 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
wisdom5034201 2006-04-06
  • 打赏
  • 举报
回复
谢谢FJINS(jin) 问题解决了 果然是驱动问题
MagicianLiu 2006-04-05
  • 打赏
  • 举报
回复
字符串中的&需要转义:
如下:
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
FJINS 2006-04-05
  • 打赏
  • 举报
回复
驱动问题,换高版本驱动
wisdom5034201 2006-04-05
  • 打赏
  • 举报
回复
zwl000906(孤独月下) 加java.sql也是一样的
我用mysql-front可以连上
my.in中的端口是3306
crystal_bb 2006-04-04
  • 打赏
  • 举报
回复
就跳出一个输入密码的界面
初始密码是多少?
zwl000906 2006-04-04
  • 打赏
  • 举报
回复
程序—Mysql—Mysql server—MySql Command Line Client,输入用户名密码即可
wisdom5034201 2006-04-04
  • 打赏
  • 举报
回复
试过了 不行啊
tiangi 2006-04-04
  • 打赏
  • 举报
回复
Connection C = DriverManager.getConnection("jdbc:mysql://localhost/news?user=rg&password=rg&useUnicode=true&characterEncoding=8859_1");
都没个端口号!加上端口号啊!

Connection C = DriverManager.getConnection("jdbc:mysql://localhost:3306/news?user=rg&password=rg&useUnicode=true&characterEncoding=8859_1");
zwl000906 2006-04-04
  • 打赏
  • 举报
回复
Connection C = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/news?user=rg&password=rg&useUnicode=true&characterEncoding=8859_1");
crystal_bb 2006-04-04
  • 打赏
  • 举报
回复
我下载了mysql-5.0.19-win32
安装好之后
在控制台输入mysqld-nt --install
重启之后还是打不开mysql
出现提示: The service already exits!
The current server installed "c:\mysql server 5.0\bin\mysqld-nt"MySQL!
请问是什么问题?
mysql安装好之后应该怎样配置才能运行?
Nuage 2006-04-04
  • 打赏
  • 举报
回复
改一下你的端口.好象是端口被占用吧!就是从新配置一下CFG!
ccwking 2006-04-04
  • 打赏
  • 举报
回复
一样的,org.gjt.mm.mysql.Driver继承了com.mysql.jdbc.Driver,都可以用的!
看你的错误信息,好像是3306端口被占用了,打开my.ini 看你mysql用的什么端口
hou_yu 2006-04-04
  • 打赏
  • 举报
回复
首先下一个mysql可视化的管理软件,网上有。
还有我想问一下
Class.forName(com.mysql.jdbc.Driver);
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
这两种是什么区别。
SkyWings82 2006-04-04
  • 打赏
  • 举报
回复
建议检查你SQLSERVER的服务端口号看看,另外看看系统进程里面有没mysqld-nt.exe进程,不要是关闭了还一个劲连接,我有个朋友就这么干过
zwl000906 2006-04-04
  • 打赏
  • 举报
回复
你写的是Connection C = DriverManager.getConnection("jdbc:mysql://localhost/news?user=rg&password=rg&useUnicode=true&characterEncoding=8859_1"); 前面应该加java.sql.
应该是Connection C = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/news?user=rg&password=rg&useUnicode=true&characterEncoding=8859_1");
wisdom5034201 2006-04-04
  • 打赏
  • 举报
回复
MySQL默认的端口是3306
jdbc:mysql://localhost:3306/news
和jdbc:mysql://localhost/news
是一样的 除非你自己改了端口
zwl000906 2006-04-04
  • 打赏
  • 举报
回复
你装的时候没密码吗?没有,应该就是123456
usherlight 2006-04-03
  • 打赏
  • 举报
回复
试一下
Class.forName(com.mysql.jdbc.Driver);

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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