jsp链接数据库老是报错,求帮忙看看什么原因
<%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%><%@pageimport="java.s...
<%@page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.sql.*"%>
<html>
<body>
<%
String tablename=request.getParameter("tablename");
if(tablename==null) tablename="";
byte[] b=tablename.getBytes("ISO-8859-1"); tablename=new String(b);
out.println(tablename);
final String DRIVER = "org.gjt.mm.mysql.Driver";
final String DURL = "jdbc:mysql://localhost:3306/application";
final String DUSER = "root";
final String DPASS = "594daidai";
Connection conn = null;
try{
Class.forName(DRIVER);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
try{
conn = DriverManager.getConnection(DURL,DUSER,DPASS);
}catch(SQLException f){
f.printStackTrace();
}
out.println(conn);
try{
conn.close();
}catch(SQLException j){
j.printStackTrace();
}
%>
</body>
</html>
org.apache.jasper.JasperException: An exception occurred processing JSP page /bookMinage/docreatetable.jsp at line 29
26: out.println("cesthi");
27: out.println(conn);
28: try{
29: conn.close();
30: }catch(SQLException j){
31: j.printStackTrace();
32: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 展开
<%@page import="java.sql.*"%>
<html>
<body>
<%
String tablename=request.getParameter("tablename");
if(tablename==null) tablename="";
byte[] b=tablename.getBytes("ISO-8859-1"); tablename=new String(b);
out.println(tablename);
final String DRIVER = "org.gjt.mm.mysql.Driver";
final String DURL = "jdbc:mysql://localhost:3306/application";
final String DUSER = "root";
final String DPASS = "594daidai";
Connection conn = null;
try{
Class.forName(DRIVER);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
try{
conn = DriverManager.getConnection(DURL,DUSER,DPASS);
}catch(SQLException f){
f.printStackTrace();
}
out.println(conn);
try{
conn.close();
}catch(SQLException j){
j.printStackTrace();
}
%>
</body>
</html>
org.apache.jasper.JasperException: An exception occurred processing JSP page /bookMinage/docreatetable.jsp at line 29
26: out.println("cesthi");
27: out.println(conn);
28: try{
29: conn.close();
30: }catch(SQLException j){
31: j.printStackTrace();
32: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询