mysql - JAVA - SQL SYNTAX ERROR -


i creating method in java. retrieve messages database keep getting syntax errors. can me?

public static string retrievemessages() {     preparedstatement pstmt;     try     {         pstmt = connection.preparestatement("select *  tblemail"                 + "innerjoin tbluser "                 +  "on tbluser.username = tblemail.`from`"                 +  "where tbluser.username = ?");          pstmt.setstring(1, user.getuser());         results = pstmt.executequery();      }     catch (sqlexception e)     {         // todo auto-generated catch block         e.printstacktrace();     }     return (results.tostring());  } 

you need add spaces (before inner , before where). spliting query multiple lines doesn't separate end of 1 row beginning of next row.

    pstmt = connection.preparestatement("select *  tblemail "                                       + "inner join tbluser "                                       +  "on tbluser.username = tblemail.`from` "                                       +  "where tbluser.username = ?"); 

when write:

                                        "select *  tblemail"                                       + "inner join tbluser " 

it same as:

                                        "select *  tblemailinner join tbluser " 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -