如何在NetBeans中查看MySQL查询的结果 [英] How to see result from mysql query in netbeans

查看:295
本文介绍了如何在NetBeans中查看MySQL查询的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在项目上运行netbeans调试器时,无法从SQL查询中看到结果表.如何以与查看其他变量相同的方式查看这些结果?

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?

以下是示例查询:

<sql:query var="query" dataSource="myDB">
SELECT * FROM data
</sql:query>
<c:set var="queryInfo" value="${query.rows[0]}"/>

如何使用debygger查看queryInfo/query表?当我尝试将结果显示为html表时,我没有收到任何错误消息,而只得到了一个空表.因此,我怀疑查询返回了一个空表.

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.

为进一步澄清,我的完整查询是:

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

查询中的第2行可能存在问题,但是我找不到param.id的问题.它可以在同一页面上的不同查询中使用.

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.

即使解决了此特定问题,我仍然想知道如何轻松地在netbeans中查看查询结果.当我使用JSP时,它不会在输出窗口中显示为变量.

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.

推荐答案

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);}   

这是连接到mysql并获取查询结果的全部代码. 希望对您有所帮助.

This is the entire code right from connecting to mysql and getting the result of your query. Hope it helps.

这篇关于如何在NetBeans中查看MySQL查询的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆