?? postlistcommand.java
字號:
package bbs;
import java.io.*;
import java.sql.*;
import COM.ibm.db2.jdbc.*;
import java.util.*;
/**
* Insert the type's description here.
* Creation date: (07/17/2001 5:07:55 PM)
* @author: Administrator
*/
public class PostListCommand {
// Field indexes for command properties
private static final int SUBJECT_COLUMN = 1;
private static final int AUTHOR_COLUMN = 2;
private static final int BOARD_COLUMN = 3;
protected Vector author = new Vector();
protected Vector subject = new Vector();
protected Vector board = new Vector();
// SQL result set
protected ResultSet result;
protected Connection connection = null;
/**
* execute
* This is the work horse method for the command.
* It will execute the query and get the result set.
*/
public void execute()
throws
java.lang.Exception,
java.io.IOException {
try {
// retrieve data from the database
Statement statement = connection.createStatement();
result =
statement.executeQuery("SELECT subject, author, board from posts");
while (result.next()) {
subject.addElement(result.getString(SUBJECT_COLUMN));
author.addElement(result.getString(AUTHOR_COLUMN));
board.addElement(result.getString(BOARD_COLUMN));
}
result.close();
statement.close();
} catch (Throwable theException) {
theException.printStackTrace();
}
}
/**
* getAuthor
* This method will get the author property.
* Since the SQL statement returns a result set,
* we will index the result.
*/
public String getAuthor(int index)
throws
java.lang.IndexOutOfBoundsException,
java.lang.ArrayIndexOutOfBoundsException {
return (String) author.elementAt(index);
}
/**
* getBoard
* This method will get the board property.
* Since the SQL statement returns a result set,
* we will index the result.
*/
public String getBoard(int index)
throws
java.lang.IndexOutOfBoundsException,
java.lang.ArrayIndexOutOfBoundsException {
return (String) board.elementAt(index);
}
/**
* getSubject
* This method will get the subject property.
* Since the SQL statement returns a result set,
* we will index the result.
*/
public String getSubject(int index)
throws
java.lang.IndexOutOfBoundsException,
java.lang.ArrayIndexOutOfBoundsException {
return (String) subject.elementAt(index);
;
}
/**
* initialize
* This method will connect to the database.
*/
public void initialize()
throws java.io.IOException {
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
// URL is jdbc:db2:dbname
String url = "jdbc:db2:board";
// connect with default id/password
connection = DriverManager.getConnection(url);
} catch (Throwable theException) {
theException.printStackTrace();
}
}
/**
* Insert the method's description here.
* Creation date: (07/17/2001 11:38:44 PM)
* @return int
* @exception java.lang.IndexOutOfBoundsException The exception description.
*/
public int getSize() {
return author.size();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -