<%
//jspexdb.setStr("hello world!");
// out.println(jspexdb.getStr());
//jspexdb = new JspexBean();
//JspexBean jBean = new JspexBean();
//jspexbean;
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://192.168.1.117:1443; DatabaseName=CRM";
String userName = "sa";
String userPwd = "mzyuan";
Connection dbConn = null;
//Connection conn = null;
try
{
Class.forName(driverName).newInstance();
out.println("驱动程序已加载");
}
catch(Exception e)
{
out.println("加载驱动程序错误...");
e.printStackTrace();
}
try
{
dbConn = DriverManager.getConnection(dbURL,userName,userPwd);
out.println("connection Successful!");
}
catch (SQLException e)
{
System.out.println("数据库连接错误...");
e.printStackTrace();
}
/*
if (null == jspexbean)
{
out.println("error");
}
else
{
out.println("success");
}
String sqlStr = "SELECT [userid],[username],[password],[email],[flag] FROM [CRM].[dbo].[user]";
ResultSet rs = jspexbean.reslutSet(null,sqlStr);
*/
String sqlStr = "SELECT userid,username,password,email,flag FROM dbo.user";
PreparedStatement pst = dbConn.prepareStatement(sqlStr);
pst.executeQuery();
ResultSetMetaData rsmd = pst.getMetaData();
out.println(rsmd.getColumnCount());
out.println(rsmd.getTableName(1));
%>
主要是在
PreparedStatement pst = dbConn.prepareStatement(sqlStr);这一句出现问题
具体问题描述如下:
message An exception occurred processing JSP page /index-ec.jsp at line 72
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /index-ec.jsp at line 72 69: ResultSet rs = jspexbean.reslutSet(null,sqlStr); 70: */ 71: String sqlStr = "SELECT userid,username,password,email,flag FROM dbo.user"; 72: PreparedStatement pst = dbConn.prepareStatement(sqlStr); 73: pst.executeQuery(); 74: ResultSetMetaData rsmd = pst.getMetaData(); 75: out.println(rsmd.getColumnCount()); Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
root cause
java.lang.NullPointerException org.apache.jsp.index_002dec_jsp._jspService(index_002dec_jsp.java:138) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:723) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
dbConn没有正常初始化好吧
debug看看排查
找到问题了。sql语句写错了
首先你要确定数据库连接是否正常,如果正常可以试试statement
找到问题了。sql语句写错了