问题
When I run the netbeans debugger on my project I can't see the resulting tables from my SQL queries. How can I see those results in the same way as I see other variables?
Here is an example query:
<sql:query var="query" dataSource="myDB">
SELECT * FROM data
</sql:query>
<c:set var="queryInfo" value="${query.rows[0]}"/>
How can I see the queryInfo/query table using the debygger? When I try to show the result as a html table I don't get any error messages and I only get an empty table. As such I suspect the query return an empty table.
EDIT: To further clarify, my full query is:
SELECT * FROM weather_station
WHERE weather_station.belong_to = ? <sql:param value="${param.id}"/>
ORDER BY when_inspected DESC
There might be a problem with line 2 in the query, but I am not able to find the walue of param.id. It works in a different query on the same page.
EDIT2: Even though this particular problem is solved, I am still wondering how I easy can see the result from a query in netbeans. When I use JSP it does not show as a variable in the output window.
回答1:
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/<database_name>","root","root");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("<Your_Query>");
while(rs.next())
System.out.println(rs.get<DataType_of_first_column>(1)+" "+rs.get<DataType_of_second_column>(2)+" "+rs.get<DataType_of_third_column>(3));
conn.close();
rs.close();
stmt.close();
}catch(Exception e){ System.out.println(e);}
This is the entire code right from connecting to mysql and getting the result of your query. Hope it helps.
来源:https://stackoverflow.com/questions/33627869/how-to-see-result-from-mysql-query-in-netbeans