Tomcat connect Mysql's question.....help
主题:Re:mysql用普通客户端能登陆么? (2004-08-09 23:49:42)
--------------------------------------------------------------------------------
我的环境是红旗linux桌面版4.0,
jakarta-tomcat-4.1.30,
mysql 4.1.0-alpha,
j2sdk1.4.2_04
mysql-connector-java-3.1.3-beta.tar.gz
我已经把mysql-connector-java-3.1.3-beta.tar.gz中的mysql-connector-java-3.1.3-beta-bin.jar拷贝到tomcat/common/lib下了。。。
并且在mysql里“grant all on anywhere.* to anywhere@'%' identified by 'anywhere';”也就是允许任何人任何地点登录mysql了,但还是出错,真是奇怪。。。
代码如下:
<%@page contentType="text/html;charset=gb2312"%>;
<%
//声名
java.sql.Connection sqlConn;
java.sql.Statement sqlStmt;
java.sql.ResultSet sqlRst;
//regiester jdbc driver
String DBUser="root";
String DBPassword="";
String DBServer="127.0.0.1"; // Can't use localhost , you must use IP or CNAME
String DBNAME="test"; // change to your db name
Class.forName("org.gjt.mm.mysql.Driver".newInstance();
//connect to the database
sqlConn=java.sql.DriverManager.getConnection("jdbc:mysql://"+DBServer+":3306/"+DBNAME+"?useUnicode=true&characterEncoding=gb2312", DBUser,DBPassword);
//create the driver handle
sqlStmt=sqlConn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
execute sql;
sqlRst=sqlStmt.executeQuery("select * from test"
%>;
<html>;
<head>;
<title>;</title>;
</head>;
<body>;
<table border="1" cellspace ="0" align="center">;
<tr>;<td>;DB CONNECT OK</td>;</tr>;
<tr>;
<th>;title</th>;
<th>;type </th>;
</tr>;
<% while(sqlRst.next()) {%>;
<tr>;
<td>;<%=sqlRst.getString(2)%>;</td>;
</tr>;
<%}%>;
</table>;
</body>;
</html>;
<%
sqlRst.close();
sqlStmt.close();
sqlConn.close();
%>;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论