java+eclipse+tomcat连接mysql数据库问题 谢谢回答 15
我把jdbc保存到tomcat\lib目录下在classpath中添加了环境变量,jsp代码如下:<%@pagecontentType="text/html;charse...
我把jdbc保存到tomcat\lib目录下 在classpath中添加了环境变量,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 = "root";
String dbName = "test";
String tableName = "student";
String url = "jdbc:mysql://192.168.1.62:3306/test?user = userName&password = userPasswd";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql = "select * from student";
ResultSet rs = statement.executeQuery(sql);
ResultSetMetaData rmeta = rs.getMetaData();
int numColumns = rmeta.getColumnCount();
out.print("id");
out.print("|");
out.print("name");
out.print("<br>");
while(rs.next()){
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();
%>
tomcat报错如下:
三月 01, 2015 4:25:02 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:DbConnection' did not find a matching property. 展开
<%@ 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 = "root";
String dbName = "test";
String tableName = "student";
String url = "jdbc:mysql://192.168.1.62:3306/test?user = userName&password = userPasswd";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql = "select * from student";
ResultSet rs = statement.executeQuery(sql);
ResultSetMetaData rmeta = rs.getMetaData();
int numColumns = rmeta.getColumnCount();
out.print("id");
out.print("|");
out.print("name");
out.print("<br>");
while(rs.next()){
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();
%>
tomcat报错如下:
三月 01, 2015 4:25:02 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:DbConnection' did not find a matching property. 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询