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可以运行,但是似乎没有访问数据库,网页显示的信息是初始化的信息,不是从数据库读取的信息,不知道是什么原因,求助各位帮忙看看.