サーブレットが初めてです。 JDBCとOJDBCでjavaを使用してデータベースに接続しようとしています。私はすでにこのためのJavaコードを書いています。今はTomcatサーバー上で実行する必要があります。サーブレットを選択しました。Netbeans IDEを使用してこれを行いました。そこでサーブレットを選択し、web.xmlにサーブレット名としてクラス名を付けました。このJavaコードをサーブレットに変換する方法
public class convert {
int i = 0, j = 0, k = 0;
Connection conn = null;
Connection connection = null;
static int count = 0;
// Following variables are required for assigning resultset values from
// excel spreadsheet
String name[] = null;
String Title[] = null;
Statement stmt1 = null;
ResultSet NumOfRows = null;
Statement stmt2 = null;
ResultSet SpreadsheetValues = null;
Statement stmt3 = null;
ResultSet rs3 = null;
int Rowcount = 0;
// this static function required to connect database
static {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(spreadsheet2db.class.getName()).log(
Level.SEVERE, null, ex);
}
}
// connect Sql database
void ConnectSqlDB() throws SQLServerException, SQLException {
// code
}
void ConnectExcelDB() throws SQLException {
conn = DriverManager.getConnection("jdbc:odbc:condb", "", "");
}
// getRowcount() will return number of rows present in spreadsheet
// Result of rowcount is used for array size
void getRowcount() throws SQLException {
// System.out.println("Number of rows in spreadsheet");
// System.out.println(Rowcount);
}
void sheetValues() throws SQLException {
stmt2 = conn.createStatement();
// ExcelQueryString2 will give values of attributes
while (SpreadsheetValues.next()) {
// Assigning Spread sheet values to String array
Cname[j] = SpreadsheetValues.getString("name");
Title[j] = SpreadsheetValues.getString("Title");
j++;
}
}
public static void main(String args[]) throws SQLServerException,
SQLException {
convert a = new convert();
a.ConnectSqlDB();
a.ConnectExcelDB();
a.getRowcount();
a.sheetValues();
}
}
私はサーブレットにこのコードを変換する方法を知りたい:私はwrong.Soをしたところ、私が働いてJavaコードを掲示しています知っているのですか?
あなたは* http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.htmlでサーブレットについての詳細を読み、自分で*コードを変換する必要があり – Manish
それを変換する必要はありません(クラス内のいくつかのバグ修正とは別に、スレッドセーフでリソースを漏らすかなりのバグがあります)。あなたはサーブレットを通常のJavaの方法と呼ぶだけです。 – BalusC