用jsp 连接 sql server 2ooo 报错如下:
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Connection reset
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.xianfeng.index_jsp._jspService(index_jsp.java:205)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
我写的代码:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.*"%>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=my";
String user="sa";
String password="123";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
GregorianCalendar timenow=new GregorianCalendar();
int year;
int month;
int day;
int hour;
int min;
int sec;
year=timenow.get(Calendar.YEAR);
month=timenow.get(Calendar.MONTH)+1;
day=timenow.get(Calendar.DAY_OF_MONTH);
min=timenow.get(Calendar.MINUTE);
sec=timenow.get(Calendar.SECOND);
hour=timenow.get(Calendar.HOUR);
request.setCharacterEncoding("gb2312");
String s=""+year+"-"+month+"-"+day+" "+hour+":"+min+":"+sec;
String title=request.getParameter("title");
String author=request.getParameter("author");
String source=request.getParameter("source");
String content=request.getParameter("content");
String type=request.getParameter("type");
String radiobutton=request.getParameter("radiobutton");
String sql="select * from news";
int i=0;
rs=stmt.executeQuery(sql);
while(rs.next()){
i=i+1;
}
i=i+1;
String sql1="INSERT INTO news(newid,title,content,author,source,datetime,newtype,isimportant) values('"+i+"','"+title+"','"+content+"','"+author+"','"+source+"','"+s+"','"+type+"','"+radiobutton+"')";
stmt.execute(sql1);
response.sendRedirect("index.jsp");
%>
</body>
</html>