Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

How to show an SQL query?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a database called CUSTOMERS. I need to show the database information using java. I have a class to make the SQL query. I have another class with get and set methods. I'm trying to initialize the data base information in this class as get and set attributes. Finally I have a class to show the database information, printing this with System.out.print. Unfortunately I can't print anything. I do not think it's a problem with SQL query, but something must be wrong. I appreciate your help.

ConnectDB.java


Data.java


ShowQuery.java
 
Saloon Keeper
Posts: 9565
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Then in your main() method you need to iterate through the list and print it. I'd suggest adding a toString() method to your Data class to facilitate that.
 
Saloon Keeper
Posts: 26047
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note: When you close a Statement, all ResultSets formed from that Statement are automatically closed. I think the same is true of Statements for a Connection, but I'd have to check the JavaDocs.

More importantly, closing a ResultSet, Statement or Connection can throw an exception. Which for Carey's example could have the unfortunate side-effect of bypassing the close operations of higher-level functions (exception on close ResultSet leaves Statement AND Connection open!) And that, in turn could leak resources. Leaking Connections is especially bad, since they tie up underlying OS sockets until the garbage collector gets around to freeing them (if ever).

So it's actually safer to close the ResultSet implicity (via the Statement close). Or, failing that, wrap each of the close method calls with its own Exception trap.

Another alternative since Java 8 is the try-with-resource feature.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand your question correctly I think this is what you are looking for?

<?php echo $GLOBALS['wp_query']->request; ?>
$wp_query is a global variable that contains the current query run by the loop. If you run the above code anytime while the loop is still active or even right after the loop it should give you the SQL from the loop. Just make sure you inspect it before letting something else run that uses query_posts() again.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This doesn't really have anything to do with PHP.
It's a standalone bit of Java.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic