LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1904|回复: 4

Resin 连接MySQL问题!

[复制链接]
发表于 2006-8-22 20:41:51 | 显示全部楼层 |阅读模式
Resin连接mysql的问题!JDBC驱动已安装好!
测试代码:test.jsp
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%
  //驱动程序名
  String driverName="com.mysql.jdbc.Driver";
  //数据库用户名
  String userName="root";
  //密码
String userPasswd="root123";
  //数据库名
  String dbName="dedev3";
  //表名
  String tableName="dede_addonimages";
  //联结字符串
  String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
  Class.forName("com.mysql.jdbc.Driver").newInstance();
  Connection connection=DriverManager.getConnection(url);
  Statement statement = connection.createStatement();
  String sql="SELECT * FROM "+tableName;
  ResultSet rs = statement.executeQuery(sql);
  //获得数据结果集合
   ResultSetMetaData rmeta = rs.getMetaData();
  //确定数据集的列数,亦字段数
   int numColumns=rmeta.getColumnCount();
  // 输出每一个数据值
out.print("id");
out.print("|");
out.print("name");
out.print("|");
out.print("address");
out.print("<br>");
while(rs.next()) {
out.print(rs.getString(1)+" ");  
out.print("|");
out.print(rs.getString(2));
out.print("|");
out.print(rs.getString(3));
out.print("<br>");
}  
out.print("<br>");
out.print("数据库操作成功,恭喜你");
rs.close();  
statement.close();  
connection.close();  
%>  



提示 :
500 Servlet Exception
com.mysql.jdbc.CommunicationsException: Communications link failure due
to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.SocketException: Permission denied

STACKTRACE:

java.net.SocketException: java.net.SocketException: Permission denied
        at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
        at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:284)
        at com.mysql.jdbc.Connection.createNewIO(Connection.java:2555)
        at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
        at java.sql.DriverManager.getConnection(DriverManager.java:525)
        at java.sql.DriverManager.getConnection(DriverManager.java:193)
        at _jsp._test__jsp._jspService(_test__jsp.java:45)
        at com.caucho.jsp.JavaPage.service(JavaPage.java:60)
        at com.caucho.jsp.Page.pageservice(Page.java:570)
        at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:175)
        at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
        at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
        at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
        at com.caucho.server.port.TcpConnection.run(TcpConnection.java:389)
        at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:507)
        at com.caucho.util.ThreadPool.run(ThreadPool.java:433)
        at java.lang.Thread.run(Thread.java:595)


** END NESTED EXCEPTION **



Last packet sent to the server was 1 ms ago.
        at com.mysql.jdbc.Connection.createNewIO(Connection.java:2621)
        at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
        at java.sql.DriverManager.getConnection(DriverManager.java:525)
        at java.sql.DriverManager.getConnection(DriverManager.java:193)
        at _jsp._test__jsp._jspService(test.jsp:19)
        at com.caucho.jsp.JavaPage.service(JavaPage.java:60)
        at com.caucho.jsp.Page.pageservice(Page.java:570)
        at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:175)
        at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
        at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
        at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
        at com.caucho.server.port.TcpConnection.run(TcpConnection.java:389)
        at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:507)
        at com.caucho.util.ThreadPool.run(ThreadPool.java:433)
        at java.lang.Thread.run(Thread.java:595)


--------------------------------------------------------------------------------
Resin-3.0.19 (built Mon, 15 May 2006 04:50:47 PDT)


我已经试了很多种办法都不行,请各位赐教!我的FreeBSD系统下测试的!
JDK版本!
java -version
java version "1.5.0-p2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-p2-root_03_dec_2005_13_18)
Java HotSpot(TM) Client VM (build 1.5.0-p2-root_03_dec_2005_13_18, mixed mode)
发表于 2006-8-22 21:29:31 | 显示全部楼层
mysql权限设置正确了吗?命令行能否连接?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-8-23 00:51:01 | 显示全部楼层
root权限~
命令行没问题!
回复 支持 反对

使用道具 举报

发表于 2006-8-23 11:38:47 | 显示全部楼层
mysql设置中是否可以允许你的IP域
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-8-23 13:32:02 | 显示全部楼层
mysql设置中是否可以允许你的IP域

是什么意思!
是不是访问MySQ的IP 主机名吗!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表