作者leo1234 (hi)
看板Database
标题[SQL ] jsp连接sql(jdbc)
时间Tue Nov 27 01:20:31 2012
各位大大不好意思~
我想请问一下这段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: //撱个亥岷銝衣椡?餜s%雂
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.24.120.205
1F:→ leo1234:已找到问题~~ 11/27 01:40