//Java bean
//file name: faq.Java
import Java.sql.*;
public class faq {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq";
Connection conn = null;
ResultSet rs = null;
public faq() {
try {
Class.forName(sDBDriver);
}catch(Java.lang.ClassNotFoundException e) {
System.err.println("faq(): " + e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
//Java Application
//file name: testfaq.Java
import Java.sql.*;
class getRs
{
public static String Answer;
public static String Subject;
public static String[][] rsArray = new String[9][2];;
public static int n = 0;
getRs(){
try {
faq workM = new faq();
ResultSet oRs = workM.executeQuery("SELECT * FROM faq");
//System.out.println(oRs.getCount());
while (oRs.next()){
System.out.println(oRs.getString("Answer"));
System.out.println(oRs.getString("Subject"));
n=n+1;
}
}catch (SQLException ex)
{
System.out.println("error:"+ex);
}
}
}
public class testfaq {
public static void main(String[] args) {
getRs aa = new getRs();
}
}
//JSP
//file name: testfaq.JSP
這是我的FAQ!
<%@ page contentType="mimeType; charset=gb2312"%>
<%@ page language="java" import="Java.sql.*" %>
<%
faq workM = new faq();
ResultSet RS = workM.executeQuery("SELECT * FROM faq");
String tt;
while (RS.next()) {
tt = RS.getString("Answer");
out.print("
out.print("
" + tt + "");
}
RS.close();
%>