我的jsp环境是:Apache Tomcat 5.5.15 Server+mysql-5.0.18-win32+jdk1.5.0_05
jdbc驱动是mysql-connector-java-3.1.12-bin.jartestdb.jsp<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%
Connection conn = null;
Class.forName("org.gjt.mm.mysql.Driver");
conn =DriverManager.getConnection("jdbc:mysql://192.168.1.17/test?user=root&password=1234&useUnicode=true&characterEncoding=GBK");
Statement stmt=conn.createStatement();
ResultSet rs=null;
String sql = "insert into test (ClassID,ParentID,ClassName) values (1,0,'新闻')";
PreparedStatement pst = conn.prepareStatement(sql);
pst.executeUpdate();
pst.close();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
</body>
</html>
<%
rs.close();
stmt.close();
conn.close();
%>
报错信息:
javax.servlet.ServletException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect不知道原因
jdbc驱动是mysql-connector-java-3.1.12-bin.jartestdb.jsp<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%
Connection conn = null;
Class.forName("org.gjt.mm.mysql.Driver");
conn =DriverManager.getConnection("jdbc:mysql://192.168.1.17/test?user=root&password=1234&useUnicode=true&characterEncoding=GBK");
Statement stmt=conn.createStatement();
ResultSet rs=null;
String sql = "insert into test (ClassID,ParentID,ClassName) values (1,0,'新闻')";
PreparedStatement pst = conn.prepareStatement(sql);
pst.executeUpdate();
pst.close();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
</body>
</html>
<%
rs.close();
stmt.close();
conn.close();
%>
报错信息:
javax.servlet.ServletException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect不知道原因
mysql的端口是3306,默认是不需要制定的。楼住还是去检查下你的mysql服务是否已经启动了。可以先用mysql命令来链接数据库试试。
skip-networking
把它注释掉(如下处理)
#skip-networking