to Unicorn008(菜之鸟) :改成你的方法后:Error: 500 Location: /web/show/access.jsp Internal Servlet Error:org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated. C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:26: Ambiguous class: java.beans.Statement and java.sql.Statement Statement odbcstmt; ^ C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:90: Class <>Statement not found in =. odbcstmt = odbcconn.createStatement(); ^ C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:90: Incompatible type for =. Can't convert java.sql.Statement to <>Statement. odbcstmt = odbcconn.createStatement(); ^ C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:92: Class <>Statement not found in void _jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse). odbcrs=odbcstmt.executeQuery(odbcQuery); ^ C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:110: Class <>Statement not found in void _jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse). odbcstmt.close(); ^ 5 errors, 1 warning
<%@ page import="java.sql.*" %>
<html>
<head>
<title>access</title>
</head>
<body>
<%
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=web.mdb";
try{
Class.forname("sun.jdbc.odbc .JdbcOdbcDriver");
Connection con=DriverManager.getConnetion(url);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT*FORM name1");
while(rs.next()){
%>
<%=re.getString(title)%>
<%}%>
<%
rs.close();
stmt.close();
con.close();
%>
<%}%>
<%catch(ClassNotFoundException e){
out.println("error!");
}
%>
</body>
</html>
另外,需要先配置一下微软的ODBC!!!
url是错误的:你从ODBC配置好一个连接到ACCESS的数据源,比如你设的名字为:SaleManage
那么url="jdbc:odbc:SaleManage"如果ACCESS设置密码的话,url="jdbc:odbc:SaleManage","用户名","密码"
import ="java.util.*"
import ="java.io.*"
import="java.text.*"
contentType="text/html; charset=gb2312"
buffer="20kb"
%><%! int all,i,m_count;
String odbcQuery;
Connection odbcconn;
Statement odbcstmt;
ResultSet odbcrs;
String username,title,content,work,email,url,time,date;
String datetime;
%>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch (ClassNotFoundException e)
{ out.print ("驱动程序不存在");
}
try{
odbcconn = DriverManager.getConnection("jdbc:odbc:db1");
odbcstmt = odbcconn.createStatement();
odbcQuery="Select * From book where datetime>2001-4-26 Order By datetime DESC";
odbcrs=odbcstmt.executeQuery(odbcQuery);
int i=0;
while (i<130) odbcrs.next();
while (odbcrs.next())
{
//*/////////////////////////显示数据库的内容用于调试程序是用//
int ii;
try{
try{
for (ii=1;;ii++)
out.print ("<br>Cloumn "+ii+" is: "+odbcrs.getString(ii));
}catch (NullPointerException e) {
out.print ("有空的指针");
}
}catch (SQLException e){
}
}
odbcrs.close();
odbcstmt.close();
odbcconn.close();
}catch (SQLException e)
{ out.print (e);
}
%>
<%@ page import="java.sql.*" %>
<%@ page import="sun.jdbc.odbc.JdbcOdbcDriver"%>
<html>
<head>
<title>access</title>
</head>
<body> <%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection odbcConn=DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=web.mdb);
Statement odbcStmt=odbcConn.createStatement();
//request.setCharacterEncoding("gb2312");
ResultSet odbcRs=odbcStmt.executeQuery( "SELECT*FORM name1" );
%>
</body>
</html>
Location: /web/show/access.jsp
Internal Servlet Error:org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:26: Ambiguous class: java.beans.Statement and java.sql.Statement
Statement odbcstmt;
^
C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:90: Class <>Statement not found in =.
odbcstmt = odbcconn.createStatement();
^
C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:90: Incompatible type for =. Can't convert java.sql.Statement to <>Statement.
odbcstmt = odbcconn.createStatement();
^
C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:92: Class <>Statement not found in void _jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse).
odbcrs=odbcstmt.executeQuery(odbcQuery);
^
C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:110: Class <>Statement not found in void _jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse).
odbcstmt.close();
^
5 errors, 1 warning
*
* 本连接数据库
*
*********************************************************************///package
package InfoDatabase;
//import
import java.sql.*;public class OpenDatabase
{
//define connection string for db: jdbc.odbc bridge
String strDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=infodb.mdb";
//DSN=2004.mdb";
//
//String strurl = "jdbc:odbc:infodb";
Connection conn = null;
ResultSet rs = null;
Statement stmt;
//open database_connection
public OpenDatabase(){
try{
Class.forName(strDBDriver);
conn = DriverManager.getConnection( strurl, "", "" );
stmt = conn.createStatement();
// System.err.println("Opendb is visited.");
}
catch( java.lang.ClassNotFoundException e ){
System.err.println( "opendb(): " + e.getMessage() );
}
catch( java.sql.SQLException e1 ){
System.err.println( "aq.executeQuery: " + e1.getMessage() );
}
}
//execute sql query: select
public ResultSet executeQuery( String sql ){
rs = null;
try{
rs = stmt.executeQuery( sql );
}
catch( SQLException e ){
System.err.println( "aq.executeQuery: " + e.getMessage() );
}
return rs;
} //execute sql update: insert, delete
public boolean executeUpdate( String sql ){
try{
stmt.executeUpdate( sql );
return true;
}
catch( SQLException e ){
System.err.println( "aq.executeUpdate: " + e.getMessage() );
}
return false;
} //execute sql count: count
public int executeCount( String sql ){
rs = null;
try{
int nCount = 0;
rs = stmt.executeQuery( sql );
while( rs.next() ){
nCount ++;
}
return nCount;
}
catch( SQLException e ){
System.err.println( "aq.executeCount: " + e.getMessage() );
}
return -1;
} //end of class Opendb
public void close(){
try{
rs.close();
stmt.close();
}
catch( Exception e ){
System.err.println( e.toString() );
}
}
//destruction
public void finalize(){
try{
rs.close();
stmt.close();
conn.close();
}
catch( Exception e ){
System.err.println( e.toString() );
}
}
}
/*********************************************************************
*
* 本连接数据库
*
*********************************************************************///package
package InfodbZ;
//import
import java.sql.*;public class aaa
{
//define connection string for db: jdbc.odbc bridge
String strDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\数据库\\名称.mdb";
//String strurl = "jdbc:odbc:infodb";
Connection conn = null;
ResultSet rs = null;
Statement stmt;
//open database_connection
public data(){
try{
Class.forName(strDBDriver);
conn = DriverManager.getConnection( strurl, "", "" );
stmt = conn.createStatement();
// System.err.println("Opendb is visited.");
}
catch( java.lang.ClassNotFoundException e ){
System.err.println( "opendb(): " + e.getMessage() );
}
catch( java.sql.SQLException e1 ){
System.err.println( "aq.executeQuery: " + e1.getMessage() );
}
}
//execute sql query: select
public ResultSet executeQuery( String sql ){
rs = null;
try{
rs = stmt.executeQuery( sql );
}
catch( SQLException e ){
System.err.println( "aq.executeQuery: " + e.getMessage() );
}
return rs;
} //execute sql update: insert, delete
public boolean executeUpdate( String sql ){
try{
stmt.executeUpdate( sql );
return true;
}
catch( SQLException e ){
System.err.println( "aq.executeUpdate: " + e.getMessage() );
}
return false;
} //execute sql count: count
public int executeCount( String sql ){
rs = null;
try{
int nCount = 0;
rs = stmt.executeQuery( sql );
while( rs.next() ){
nCount ++;
}
return nCount;
}
catch( SQLException e ){
System.err.println( "aq.executeCount: " + e.getMessage() );
}
return -1;
} //end of class Opendb
public void close(){
try{
rs.close();
stmt.close();
}
catch( Exception e ){
System.err.println( e.toString() );
}
}
//destruction
public void finalize(){
try{
rs.close();
stmt.close();
conn.close();
}
catch( Exception e ){
System.err.println( e.toString() );
}
}
}
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=web.mdb";
try{
Class.forname("sun.jdbc.odbc .JdbcOdbcDriver");
Connection con=DriverManager.getConnetion(url);
.......
}catch(SQLException e){}
String sConnStr =
"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=provider.dat";//provider.dat这个是你的数据库,可以改成绝对路径
Class.forName(sDBDriver).newInstance();newInstance();这个去哪了?
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.sql.*" %>
<%@ page import="sun.jdbc.odbc.JdbcOdbcDriver"%>
<html>
<head>
<title>access</title>
</head>
<body>
<% String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=web.mdb";
try{
Class.forName("sun.jdbc.odbc .JdbcOdbcDriver").newInstance();
Connection con=DriverManager.getConnetion(url);
System.out.println("123");
Statement stmt = con.createStatement();
String sql="SELECT*FORM name1";
ResultSet rs = stmt.executeQuery(sql);
}catch(SQLException e){
out.println("123");
}
%>
</body>
</html>
错误信息:org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:72: Method getConnetion(java.lang.String) not found in class java.sql.DriverManager.
Connection con=DriverManager.getConnetion(url);
^
C:\TOMCAT\work\localhost_8080%2Fweb\_0002fshow_0002faccess_0002ejspaccess_jsp_0.java:74: Ambiguous class: java.beans.Statement and java.sql.Statement
Statement stmt = con.createStatement();
^
2 errors, 1 warning