Results 1 to 3 of 3
  1. #1
    kitiaradl is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default return output from a non select query (java/access)

    I'm trying to return my entire database as a result of the following..but i'm not getting any results back..I also want to clear the text area/field once result are returned..

    I have attached my java and database files.

    Here is the code below where I am having the challenge. If enter "select * from students" then it will return something, but if i do anything else, it wont return anything.


    public String query(String query){
    String output = "";

    String[] temp = query.split(" ");
    try{
    if(!temp[0].equalsIgnoreCase("select")){
    statement.executeUpdate(query);
    //query("SELECT * FROM students");

    return output;


    }
    else{
    resultSet = statement.executeQuery(query);
    output = formatResult();
    return output;


    }
    }
    catch(SQLException sqle){

    JOptionPane.showMessageDialog(null, sqle);

    }

    return output;
    }

    private String formatResult(){
    String output = "";



    try{
    while(resultSet.next()){
    output += resultSet.getString("Fname") + " " +
    resultSet.getString("Lname") + " " +
    resultSet.getInt("Age") + "\n";




    }
    }
    catch(SQLException sqle){

    System.err.print(sqle);

    }
    return output;
    }
    Attached Files Attached Files

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    non-select queries have no output... not sure what you're trying to accomplish

  3. #3
    kitiaradl is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    right, so how do i get it to return all of the information in the database? And clear the field once any statement is executed? I assume it has to be coded for when someone click the execute query button.

Similar Threads

  1. return output from a non select query (java/access)
    By kitiaradl in forum New To Java
    Replies: 0
    Last Post: 04-15-2010, 09:01 PM
  2. Java Native Access (JNA) return types of void *
    By burnumd in forum Advanced Java
    Replies: 5
    Last Post: 01-15-2010, 12:09 AM
  3. SELECT FROM WHERE query
    By herfnai in forum JDBC
    Replies: 3
    Last Post: 11-24-2008, 11:04 AM
  4. problem in select query
    By herfnai in forum JDBC
    Replies: 0
    Last Post: 08-17-2008, 11:47 AM
  5. Using a variable in a SELECT FROM WHERE query
    By cplmckenzie in forum JDBC
    Replies: 12
    Last Post: 04-23-2008, 03: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
  •