Results 1 to 1 of 1
  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
    Last edited by kitiaradl; 04-20-2010 at 06:48 PM. Reason: attachment

Similar Threads

  1. Java Native Access (JNA) return types of void *
    By burnumd in forum Advanced Java
    Replies: 5
    Last Post: 01-15-2010, 01:09 AM
  2. MySQL/JDBC Prepared Statement Select query
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-12-2009, 06:29 PM
  3. SELECT FROM WHERE query
    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
  •