jsp链接数据库问题
jsp代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test_sql.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*"%>
<%!
Connection con;
Statement sql;
ResultSet rs;
%>
<%
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;DatabaseName=mis";
con=DriverManager.getConnection(url,"sa","sa");
sql=con.createStatement();
String sqlexe="select * from identity_check";
rs=sql.executeQuery(sqlexe);
rs.next();
out.println(rs.getString(1));
out.println("数据库连接成功!");
%>
</body>
</html>
出现的问题为:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /test_sql.jsp at line 37
34:
35: Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
36: String url="jdbc:sqlserver://localhost:1433;DatabaseName=mis";
37: con=DriverManager.getConnection(url,"sa","sa");
38: sql=con.createStatement();
39: String sqlexe="select * from identity_check";
40: rs=sql.executeQuery(sqlexe);
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
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.lang.UnsupportedOperationException: 此驱动程序不支持 Java Runtime Environment (JRE) 1.6 版。请使用支持 JDBC 4.0 的 sqljdbc4.jar 类库。
com.microsoft.sqlserver.jdbc.SQLServerConnection.<init>(SQLServerConnection.java:223)
com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:840)
java.sql.DriverManager.getConnection(DriverManager.java:582)
java.sql.DriverManager.getConnection(DriverManager.java:185)
org.apache.jsp.test_005fsql_jsp._jspService(test_005fsql_jsp.java:98)
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:393)
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)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
Apache Tomcat/6.0.13
求教如何解决!!!!!
[解决办法]
你当前的jar版本不支持。换sqljdbc4.jar
[解决办法]
换个jar包吧。网上重新下个。
[解决办法]
自己先看看错误代码吧!
[解决办法]
换个驱动包试试。。
[解决办法]
请使用支持 JDBC 4.0 的 sqljdbc4.jar 类库。
已经说的很清楚了
[解决办法]
java.lang.UnsupportedOperationException: 此驱动程序不支持 Java Runtime Environment (JRE) 1.6 版。请使用支持 JDBC 4.0 的 sqljdbc4.jar 类库。
第一次看到中文的异常提示啊,我out了