[求助]JSP 连接数据库(SQL SERVER) 连不上的问题,谢谢指点。
<%@page contentType="text/html" pageEncoding="UTF-8"%><%@page import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册信息返回</title>
</head>
<body>
<%
String sql="";
try{
out.println("<h1>Begin</h1>");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
out.println("<h1>OK</h1>");
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ODBCmyTest";
Connection dbConn= DriverManager.getConnection(url);
out.println("<h1>yes</h1>");
Statement stmt=dbConn.createStatement();
ResultSet rs=null;
String sUserName=request.getParameter("UserName");
sql="select * from users where userName llike '"+sUserName+"'";
rs=stmt.executeQuery(sql);
if(rs.next()){
out.println("<h1 align=center>用户名<font color=blue>"+sUserName
+"</font>已经存在</h1>");
out.println("<div align=center><input type=buttom name=btn" +
"value=返回 onClick='window.history.go(-1)'></div>" );
}else{
String sUserPassword=request.getParameter("UserPassword");
String sNickName=request.getParameter("NickName");
String sGender=request.getParameter("Gender");
String sEmail=request.getParameter("Email");
sql="inset into users(userName,userPassword,nickName,gender,email) " +
"values('"+sUserName+"','"+sUserPassword+
"','"+sNickName+"','"+sGender+"','"+sEmail+"')";
stmt.executeUpdate(sql);
out.println("<h2 align=center>注册成功</h2>");
}
rs.close();
stmt.close();
dbConn.close();
}catch(Exception e){
out.println("<h1>出现错误,注册失败!</h1>");
}
%>
</body>
</html>
输出结果是:
Begin
出现错误,注册失败!
也就是说 Class.forName 就错了 是不是我的数据库需要什么设置?
我的数据源配了的 名字是ODBCmyTest