📄 compounndjspcommand.java
字号:
package bbs;
import java.io.*;
import java.sql.*;
import COM.ibm.db2.*;
import java.util.*;
/**
* Insert the type's description here.
* Creation date: (07/17/2001 5:07:55 PM)
* @author: Administrator
*/
public class CompoundJSPCommand {
// 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 String board = null;
// 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.io.IOException {
try {
// retrieve data from the database
Statement statement = connection.createStatement();
result =
statement.executeQuery(
"SELECT subject, author, board from posts where board = '"
+ getBoard() + "'");
while (result.next()) {
subject.addElement(result.getString(SUBJECT_COLUMN));
author.addElement(result.getString(AUTHOR_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() {
return board;
}
/**
* 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();
}
/**
* 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();
}
}
/**
* getBoard
* This method will get the board property.
* Since the SQL statement returns a result set,
* we will index the result.
*/
public void setBoard(String name) {
board=name;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -