Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32
  1. #21
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: SQL Display statement

    Well, the column_names is just an example, * works fine for you. But yes, that where is unnecessary. But there are other differences, what about the "from" clause and those parenthesis?

  2. #22
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL Display statement

    My statement now looks like this:
    Java Code:
    displayMthd("SELECT * FROM Table1, Table2 INNER JOIN Table2 ON Table1.Player = Table2.Player");
    And I get the following error:
    Java Code:
    SQL3.java:19: method displayMthd in class SQL3 cannot be applied to given types;
          	displayMthd("SELECT * FROM Table1, Table2 INNER JOIN Table2 ON Table1.Player = Table2.Player");
          	^
      required: String,String
      found: String
      reason: actual and formal argument lists differ in length
    1 error
    Or shouuld it look like this?:
    Java Code:
    displayMthd("SELECT * INNER JOIN Table2 ON Table1.Player = Table2.Player");
    Then I get the same errors.

  3. #23
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: SQL Display statement

    Close, your from clause only needs to have table1 -
    Java Code:
    SELECT * FROM Table1 INNER JOIN Table2 ON Table1.Player = Table2.Player
    I don't know what displayMthd does, but earlier you were calling it this way
    Java Code:
    displayMthd("All players","SELE..");
    Are you missing a parameter?

  4. #24
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL Display statement

    Ahw thank you so much!! I am calling that class from another class and I want a JOptionPaneMessageDialog to show the information, but in the loop it is going to display 3 times...any other way I can do this?
    Java Code:
     void displayMthd (String heading, String sqlStmt) throws SQLException
          {
             stmt = conn.createStatement();		//Standard method from Statement class
             ResultSet rs = stmt.executeQuery(sqlStmt);   //Method from Resultset class (also update query)
               
             System.out.println();
             System.out.println(heading);
             System.out.println();
             while (rs.next())
             {
                String p1 = rs.getString("Player");
                String op = rs.getString("Opponent");
                String dat = rs.getString("Date");
                String mot = rs.getString("Motto");
                String dob = rs.getString("Dateofbirth");
                String pob = rs.getString("Placeof birth");
                String mem = rs.getString("Member");
                String rnk = rs.getString("Rank");
                String gen = rs.getString("Gender");
                
                System.out.println(p1+"\t"+op+"\t"+dat);
             }
             System.out.println();   
             stmt.close();
          }
    if i put it there at the second System.out.println it gives an error.

  5. #25
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: SQL Display statement

    If you want to display the text in a JOptionPaneMessageDialog, why are you printing it to the console? What error are you getting?

  6. #26
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL Display statement

    What is the console? It says cannot find symbol to every object it gor from the database that I am trying to display.

  7. #27
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: SQL Display statement

    The console/terminal is what System.out writes to, displays the text output.

    Did you try to find out what the error message means?
    Java error cannot find symbol

  8. #28
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL Display statement

    I did try and declare it but it didn't work.

  9. #29
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: SQL Display statement

    Read the error message, what line is it having an issue with/what symbol does it not recognize?

  10. #30
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: SQL Display statement

    Every Symbol that that I get from the database it can't find. Look:
    Java Code:
    void displayMthd (String heading, String sqlStmt) throws SQLException
          {
             stmt = conn.createStatement();		//Standard method from Statement class
             ResultSet rs = stmt.executeQuery(sqlStmt);   //Method from Resultset class (also update query)
               
             System.out.println();
             System.out.println(heading);
             System.out.println();
             while (rs.next())
             {
                String p1 = rs.getString("Player");
                String op = rs.getString("Opponent");
                String dat = rs.getString("Date");
                String mot = rs.getString("Motto");
                String dob = rs.getString("Dateofbirth");
                String pob = rs.getString("Placeofbirth");
                String mem = rs.getString("Member");
                String rnk = rs.getString("Rank");
                String gen = rs.getString("Gender");
             }
             JOptionPane.showMessageDialog(null,"Player:  "+p1+"\nOpponent:  "+op+"\nDate played:  "+dat+"\nMotto:  "+mot+"\nDate of birth:  "+dob+"\nPlace of birth:  "+pob+"\nMember of:  "+mem+"\nRank:  "+rnk+"\nGender:  "+gen);
          
             System.out.println();   
             stmt.close();
          }
    Java Code:
    SQL3.java:67: cannot find symbol
             JOptionPane.showMessageDialog(null,"Player:  "+p1+"\nOpponent:  "+op+"\nDate played:  "+dat+"\nMotto:  "+mot+"\nDate of birth:  "+dob+"\nPlace of birth:  "+pob+"\nMember of:  "+mem+"\nRank:  "+rnk+"\nGender:  "+gen);
                                                            ^
      symbol:   variable p1
      location: class SQL3
    SQL3.java:67: cannot find symbol
             JOptionPane.showMessageDialog(null,"Player:  "+p1+"\nOpponent:  "+op+"\nDate played:  "+dat+"\nMotto:  "+mot+"\nDate of birth:  "+dob+"\nPlace of birth:  "+pob+"\nMember of:  "+mem+"\nRank:  "+rnk+"\nGender:  "+gen);
                                                                               ^
      symbol:   variable op
      location: class SQL3
    SQL3.java:67: cannot find symbol
             JOptionPane.showMessageDialog(null,"Player:  "+p1+"\nOpponent:  "+op+"\nDate played:  "+dat+"\nMotto:  "+mot+"\nDate of birth:  "+dob+"\nPlace of birth:  "+pob+"\nMember of:  "+mem+"\nRank:  "+rnk+"\nGender:  "+gen);
                                                                                                     ^
      symbol:   variable dat
      location: class SQL3
    SQL3.java:67: cannot find symbol
             JOptionPane.showMessageDialog(null,"Player:  "+p1+"\nOpponent:  "+op+"\nDate played:  "+dat+"\nMotto:  "+mot+"\nDate of birth:  "+dob+"\nPlace of birth:  "+pob+"\nMember of:  "+mem+"\nRank:  "+rnk+"\nGender:  "+gen);
                                                                                                                      ^
      symbol:   variable mot
      location: class SQL3
    SQL3.java:67: cannot find symbol
             JOptionPane.showMessageDialog(null,"Player:  "+p1+"\nOpponent:  "+op+"\nDate played:  "+dat+"\nMotto:  "+mot+"\nDate of birth:  "+dob+"\nPlace of birth:  "+pob+"\nMember of:  "+mem+"\nRank:  "+rnk+"\nGender:  "+gen);
                                                                                                                                               ^
      symbol:   variable dob
      location: class SQL3
    SQL3.java:67: cannot find symbol
             JOptionPane.showMessageDialog(null,"Player:  "+p1+"\nOpponent:  "+op+"\nDate played:  "+dat+"\nMotto:  "+mot+"\nDate of birth:  "+dob+"\nPlace of birth:  "+pob+"\nMember of:  "+mem+"\nRank:  "+rnk+"\nGender:  "+gen);
                                                                                                                                                                         ^
      symbol:   variable pob
      location: class SQL3
    SQL3.java:67: cannot find symbol
             JOptionPane.showMessageDialog(null,"Player:  "+p1+"\nOpponent:  "+op+"\nDate played:  "+dat+"\nMotto:  "+mot+"\nDate of birth:  "+dob+"\nPlace of birth:  "+pob+"\nMember of:  "+mem+"\nRank:  "+rnk+"\nGender:  "+gen);
                                                                                                                                                                                              ^
      symbol:   variable mem
      location: class SQL3
    SQL3.java:67: cannot find symbol
             JOptionPane.showMessageDialog(null,"Player:  "+p1+"\nOpponent:  "+op+"\nDate played:  "+dat+"\nMotto:  "+mot+"\nDate of birth:  "+dob+"\nPlace of birth:  "+pob+"\nMember of:  "+mem+"\nRank:  "+rnk+"\nGender:  "+gen);
                                                                                                                                                                                                              ^
      symbol:   variable rnk
      location: class SQL3
    SQL3.java:67: cannot find symbol
             JOptionPane.showMessageDialog(null,"Player:  "+p1+"\nOpponent:  "+op+"\nDate played:  "+dat+"\nMotto:  "+mot+"\nDate of birth:  "+dob+"\nPlace of birth:  "+pob+"\nMember of:  "+mem+"\nRank:  "+rnk+"\nGender:  "+gen);
                                                                                                                                                                                                                                ^
      symbol:   variable gen
      location: class SQL3
    9 errors

  11. #31
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: SQL Display statement

    None of those errors have to do with the values pulled from database -
    Java Code:
    SQL3.java:67: cannot find symbol
      JOptionPane.showMessageDialog(null,"Play...
      symbol:   variable op
      location: class SQL3
    It says "cannot find symbol" and tells you directly that the symbol it doesn't know is the variable "op". That means it doesn't know what that variable is and doesn't think it has been declared.

    The reason it can't find it is because of scope. Since you declared your variables (op, p1, etc..) in the while loop, they'll only exist in the while loop and you'll be unable to reference them outside of it. To fix your problem you need to declare your variables outside of the loop or simply move the JOptionPane.showMessageDialog call inside the loop.

  12. #32
    Mr777 is offline Devil
    Join Date
    Nov 2011
    Location
    Pakistan
    Posts
    12
    Rep Power
    0

    Default Re: SQL Display statement

    Well, well, well...
    Divide your problem into sub problems like;
    1. Try SELECT * FROM table1, table2 (without any joins).
    And hopefully there must be cross joined data but don't worry. You first have to check if query is working properly or not.
    2. After that try SELECT * FROM table1, table WHERE table1.key1=table2.key1 etc (Don't use INNER JOIN but make it on your own)
    And then try the result.
    3. After successful compilation of your program, you must use your very own query.

    Post the results with all the three cases so that we could check the behaviour.
    Good Luck.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 1
    Last Post: 12-01-2010, 07:35 PM
  2. Using the return statement to display a string
    By Hoverboy in forum New To Java
    Replies: 6
    Last Post: 11-17-2010, 10:22 AM
  3. Replies: 1
    Last Post: 05-31-2010, 09:46 AM
  4. Replies: 8
    Last Post: 12-29-2008, 08:12 AM
  5. Replies: 0
    Last Post: 01-04-2008, 10:32 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
  •