连接到SQLServer 2008 R2期间发生jasper异常

时间:2011-05-23 10:10:43

标签: java sql jsp jdbc

<%@page import="java.sql.*"%>

<form name="form" method="post" >
<b>Select a country:</b> </td>
<select name="sel"><option value=""><---Select---></option>
<%
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();


Connection con=DriverManager.getConnection("jdbc:jtds:sqlserver://subversion/sql2k8:1433/career","sa","Cloud#123");

PreparedStatement psmnt = con.prepareStatement("select * from country ");
ResultSet results = psmnt.executeQuery();
while(results.next()){
String name = results.getString(2);
 String id = results.getString(1);
%><option value="<%= name %>"><%=name%></option>
<%} results.close(); psmnt.close(); %>
</select><br>

并出现错误: -

org.apache.jasper.JasperException: An exception occurred processing JSP page /1.dropdown_insert.jsp at line 13

10: 
11: 
12: 
13: Connection con=DriverManager.getConnection("jdbc:jtds:sqlserver://subversion/sql2k8:1433/career","sa","Cloud#123");
14: 
15: PreparedStatement psmnt = con.prepareStatement("select * from country ");
16: ResultSet results = psmnt.executeQuery();

堆栈跟踪:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:519)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
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:717)

1 个答案:

答案 0 :(得分:0)

  1. 检查连接字符串 - jdbc:jtds:sqlserver :// subversion / sql2k8 :1433/career
  2. 使用try-catch阻止和printstacktrace来获取正确的错误信息。