jsp连接mysql报错,org.apache.jasper.JasperException: Unable to compile class for JSP
//驱动程序名
String driverName="com.mysql.jdbc.Driver";
//数据库用户名
String userName="";
//密码
String userPasswd="";
//数据库名
String dbName="";
//表名
String tableName="";
//联结字符串
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("username");
out.print("| ");
out.print("password");
out.print("
");
while(rs.next()) {
out.print(rs.getString(1));
out.print(" | ");
out.print(rs.getString(2));
out.print(" | ");
out.print(rs.getString(3));
out.print("
");
}
out.print("
");
out.print("数据库操作成功,恭喜你");
rs.close();
statement.close();
connection.close();
%>
最后确定是java home等相关变量未建立
java_home=
classpath=
path=
重启tomcat即可。