[請益] jsp連接資料庫(JDBC)
各位大大不好意思~
我想請問一下這段JSP連接資料庫哪裡有問題~
我用了好久都無法成功~
希望有高手可以指點我一下~
感恩^^
我的TABLE是access_log
裡面存了injected_string 和 parameter 這兩個欄位 (還有uid)
不過好像49行開始就有問題
已經有確認jdbc有成功連接了
String user = "xxx";
String pass = "xxx";
String database = "defense";
String url = "jdbc:mysql://localhost:3306/defense";
//建立一個聯結物件
Connection conn;
//建立Statement物件,建立陳述式物件
Statement stmt;
try{
//定義驅動程式與資料來源之間的連結
Class.forName("com.mysql.jdbc.Driver").newInstance();
//建立一個聯結物件
conn = DriverManager.getConnection(url,user,pass);
//建立Statement物件
stmt = conn.createStatement();
}catch(SQLException sqle){
out.println("SQL Exception : " + sqle);
}
//建立查詢並產生rs的資料表
//String sql = "select * from access_log";
ResultSet rs = stmt.executeQuery("select * from access_log"); --->line 49
//開始顯示
while(rs.next()){
String name = rs.getString("injected_string");
String num = rs.getString("parameter");
out.print("Name : " + name + " Num : " + num + "<br>");
}
//關閉資料表
rs.close();
錯誤訊息:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it
from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 49 in the jsp file: /Rule2.jsp
The local variable stmt may not have been initialized
46: }
47: //撱箇nection conn;
//建立Statement物件,建立陳述式物件
Statement
stmt;
try{
//定義驅動程式與資料來源之間的連
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.24.120.205
→
11/27 01:40, , 1F
11/27 01:40, 1F
→
11/27 09:36, , 2F
11/27 09:36, 2F
推
11/27 09:49, , 3F
11/27 09:49, 3F
→
11/27 11:18, , 4F
11/27 11:18, 4F
→
11/29 05:42, , 5F
11/29 05:42, 5F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章