Page 1 of 1

MySql SELECT

Posted: 09 Jul 2011, 19:34
by Zerano
Hello i have created 2 tabeles and set the relationship between them:
Image

and now i wont to get the data(name) from the character tabel based on the username.

but i do not know how to do the query for it. i have tried this:

Code: Select all

   PreparedStatement new_sql = conn.prepareStatement("SELECT * FROM user LEFT JOIN character ON user.iduser=character.iduser WHERE user.username=?");
            new_sql.setString(1, username);
            ResultSet new_result = new_sql.executeQuery();
            new_result.first();
            String name = (String) new_result.getString(0);
            trace(name);
but it doesn't work.

i hope you can help me.