서블릿을 처음 사용합니다. JDBC 및 OJDBC와 함께 java를 사용하여 데이터베이스에 연결하려고합니다. 나는 이것을 위해 이미 자바 코드를 작성했다. 이제 Tomcat 서버에서 실행해야합니다. 그래서 서블릿을 선택했습니다. Netbeans IDE를 사용하여이 작업을 수행했습니다. 서블릿을 선택했고 web.xml에서 서블릿 이름으로 클래스 이름을 지정했습니다.이 자바 코드를 서블릿으로 변환하는 방법
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을했던 곳, 내가 작업 자바 코드를 게시하고 몰라?
당신은 http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html에서 서블릿에 대한 자세한 내용을 다음 – Manish
자신의 *에 코드 * 변환해야 그것을 변환 할 필요가 없습니다 (클래스의 여러 버그 픽스를 제외하고, threadunsafe 및 resource-leaking을 만드는 꽤 중요한 버그가 있습니다). 서블릿이 일반적인 Java 방식이라고 부릅니다. – BalusC