JSP连接SQL数据库出现的错误

来源:百度知道 编辑:UC知道 时间:2024/06/14 19:44:24
我的JSP代码如下:
<body>
<%
String name=(String)request.getParameter("username");
String pass=(String)request.getParameter("userpass");
String s=(String)request.getParameter("userselect");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=xk";
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=null;
String loginNum="0";
session.setAttribute("lnum",loginNum);
try
{
if(s.equals("1"))
{
String sql="select * from student where sId='"+name+"' and sPass='"+pass+"'";
stmt=conn.createStatem

可能是数据库那错了吧,你用的是2000的数据库

不知道你的sp4补丁打了没有,如果没有就不能

用1433端口的。除非你用的2003的系统

这个是一个空指针异常,错误信息太少了,不怎么好解决

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
把newInstance()去掉.
应该就这个问题
如果还是连接不上,可以参考aids514的回答