在线等__求教JSP连接ACCESS数据库的问题___谢谢各位高手帮忙解答
JavaBean 代码:
package test;
import java.sql.*;
public class TestBean{
private String trip_address= "address ";
private String trip_introduce= "introduce ";
public TestBean(){
this.ContectDB();
}
public String getAddress(){
return this.trip_address;
}
public String getIntroduce(){
return this.trip_introduce;
}
public void ContectDB(){
this.trip_address= "a ";
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
Connection conn=DriverManager.getConnection( "jdbc:odbc:trip ");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql= "select * from information where address= ' "+this.trip_address+ " ' ";
ResultSet rs=stmt.executeQuery(sql);
rs.first();
this.trip_address=rs.getString( "address ");
this.trip_introduce=rs.getString( "introduce ");
rs.close();
stmt.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
TestBean.jsp文件代码如下:
<%@ page import= "test.TestBean " %>
<html>
<body>
<center>
<%
TestBean testBean=new TestBean();
%>
Address: <%=testBean.getAddress()%>
Introduce: <%=testBean.getIntroduce()%>
</center>
</body>
</html>
用Tomcat可以运行,但是似乎没有访问数据库,网页显示的信息是初始化的信息,不是从数据库读取的信息,不知道是什么原因,求助各位帮忙看看.
------解决方案--------------------在你JSP中的那个TestBean testBean=new TestBean();
改成 test.TestBean testBean=new test.TestBean();
------解决方案--------------------jdbc-odbc桥没问题