一个数据库连接问题!
代码:
<%@ page contentType= "text/html;charset=gb2312 " %>
<%@ page import= "java.sql.* " %>
<html>
<body>
<%
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb ";
String user= "sa ";
String password= " ";
Connection conn=DriverManager.getConnection(url,user,password);
Statement
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql= "select*from test ";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){%>
第一个字段内容为: <%=rs.getString(1) %>
第二个字段内容为: <%= rs.getString(2) %>
<%}%>
<% out.print( "数据库操作成功,恭喜你 "); %>
<%
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
错误提示:
org.apache.jasper.JasperException: An exception occurred processing JSP page /connection.jsp at line 10
7: String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb ";
8: String user= "sa ";
9: String password= " ";
10: Connection conn=DriverManager.getConnection(url,user,password);
11: Statement
12: stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
13: String sql= "select*from test ";
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handle
JspException(JspServletWrapper.java:515)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用户 'sa ' 登录失败。原因: 未与信任 SQL Server 连接相关联。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.connection_jsp._jspService(connection_jsp.java:96)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.sql.
SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用户 'sa ' 登录失败。原因: 未与信任 SQL Server 连接相关联。
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSLoginRequest.processReplyToken(Unknown Source)