jsp代码,jsp连接sql server 2008
<%@pagelanguage="java"import="java.util.*"contentType="text/html;charset=gb2312"pageE...
<%@ page language="java" import="java.util.*"
contentType="text/html; charset=gb2312" pageEncoding="gb2312"%>
<%@ page import="java.sql.*"%>
<%
String driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //"oracle.jdbc.driver.OracleDriver";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=my_BookAdminuser";//"jdbc:oracle:thin:@127.0.0.1:1521:oracle";
String user = "zy";
String password = "806806";
Class.forName("java.lang.String");
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from my_BookAdminuser");
while (rs.next()) {
System.out.print("名称: " + rs.getString(1));
System.out.print("\tpassword: " + rs.getString(2));
System.out.println();
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /t.jsp:12
9: String password = "806806";
10: Class.forName("java.lang.String");
11:
12: Connection conn = DriverManager.getConnection(url, user, password);
13: Statement stmt = conn.createStatement();
14: ResultSet rs = stmt.executeQuery("select * from my_BookAdminuser");
15:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.t_jsp._jspService(t_jsp.java:75)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
。。。。。。。。。。。。。。
已经改为Class.forName(driverClass)
还是那里有错 展开
contentType="text/html; charset=gb2312" pageEncoding="gb2312"%>
<%@ page import="java.sql.*"%>
<%
String driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //"oracle.jdbc.driver.OracleDriver";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=my_BookAdminuser";//"jdbc:oracle:thin:@127.0.0.1:1521:oracle";
String user = "zy";
String password = "806806";
Class.forName("java.lang.String");
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from my_BookAdminuser");
while (rs.next()) {
System.out.print("名称: " + rs.getString(1));
System.out.print("\tpassword: " + rs.getString(2));
System.out.println();
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /t.jsp:12
9: String password = "806806";
10: Class.forName("java.lang.String");
11:
12: Connection conn = DriverManager.getConnection(url, user, password);
13: Statement stmt = conn.createStatement();
14: ResultSet rs = stmt.executeQuery("select * from my_BookAdminuser");
15:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.t_jsp._jspService(t_jsp.java:75)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
。。。。。。。。。。。。。。
已经改为Class.forName(driverClass)
还是那里有错 展开
展开全部
Class.forName("java.lang.String");
括号里应该跟上驱动吧。。
String driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
这个是驱动 所以同1楼那样
括号里应该跟上驱动吧。。
String driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
这个是驱动 所以同1楼那样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Class.forName(driverClass)
这句应该是这样子的吧...
这句应该是这样子的吧...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询