JSP+javaBean連線資料庫的問題

黃藤酒發表於2006-11-27
執行的時候就顯示一張白板,什麼結果都沒有,我就是想只要能連線到資料庫並且顯示內容就可以,請問是哪裡出問題了?
b.jsp:
<%@ page import="java.sql.*" %>

<jsp:useBean id = "myBean" class = "n.M" scope = "application" />
<%
ResultSet rs = myBean.execute("select * from b");
out.println(rs.getString(1));
%>

M.java:

package n;
import java.sql.*;

public class M
{
String DBDriver = "sun.jdbc.odbc.JdbcOdbcDirver";
String url = "jdbc:odbc:MS Access Database;DBQ=d:\\b.mdb";
Connection conn = null;
ResultSet rs = null;
public M()
{
try
{
Class.forName(DBDriver);
}
catch(Exception e){}
}

public ResultSet execute(String sql)
{
try
{
conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(Exception e){}
return rs;
}
}

相關文章