Results 1 to 3 of 3
  1. #1
    WishBone101 is offline Member
    Join Date
    Jun 2012
    Rep Power

    Default Multiple SELECT Query issue

    Hey everyone, I'm new to the forum and pretty new in java so forgive me and correct me on any of my mistakes.
    Anyway, I need to use multiple SELECT statements to retrieve data from a MySQL database but I'm getting issues. I can run a query using one SELECT statement and it works. Also, I added "?allowMultiQueries=true" in my connection statement which fixed some issues. Here is some of my code under the class

    public ResultSet getData() throws SQLException{
    String query = "USE snort_warehouse;" + "SELECT target_stats.server_id,, attack_stats.attacker, attack_stats.sig_name FROM target_stats JOIN attack_stats ON AND target_stats.interval_id=attack_stats.interval_id Where target_stats.interval_id>'2'";
    Statement stmt = con.createStatement();
    ResultSet rslt = stmt.executeQuery(query);

    and in my main I have:

    Database Warehouse=new Database();
    ResultSet rslt=Warehouse.getData();
    while ({
    String server_id = rslt.getString("server_id");
    String target = rslt.getString("target");
    //I would continue this using all pieces of data grabbed from SQL statement
    System.out.print(server_id+"\t"+target +"\n");

    My query using the join works in the MySQL browser but i get the following errors:
    Exception in thread "main" java.sql.SQLException: ResultSet is from UPDATE. No Data.
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro
    at va:7021)
    at SnortMonitor.main(

    any help would be great. again sorry for any rookie mistakes

  2. #2
    gauravfzd's Avatar
    gauravfzd is offline Member
    Join Date
    Oct 2010
    Rep Power

    Default Re: Multiple SELECT Query issue

    Why don't you use multiple objects of PreparedStatement class for multiple queries.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Multiple SELECT Query issue

    Because one query is better than multiple ones.
    Do on the database what can be done on the database. Don't duplicate stuff the database is good at in Java.

    Anyway, for the OP, first off can you please use [code] tags [/code] when posting code.
    Second, that USE clause has turned your SQL into a CallableStatement. It is, in effect, a pseudo-procedure.
    And since your proceudre doesn't return a result set, you get that error.
    I would recommend removing the USE clause.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 06-21-2011, 05:55 PM
  2. Problem executing SELECT query
    By mike_ledis in forum JDBC
    Replies: 2
    Last Post: 04-26-2011, 06:30 AM
    By herfnai in forum JDBC
    Replies: 3
    Last Post: 11-24-2008, 12:04 PM
  4. problem in select query
    By herfnai in forum JDBC
    Replies: 0
    Last Post: 08-17-2008, 12:47 PM
  5. Using a variable in a SELECT FROM WHERE query
    By cplmckenzie in forum JDBC
    Replies: 12
    Last Post: 04-23-2008, 04:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts