I am stuck with the following code, and I don't see why I get an exception.
The string runs fine when I put it into the SQL field of phpMyAdmin.
And I receive a table as I expect, namely the table cid with 1 value, the playerID.
I also used this code in variations where I say "WHERE playerID = " +playerID
and that works....
So am really excited why this does not work when I run it through eclipse.
Yes, I did search here, found a lot of similar MySQLSyntaxErrorException threads but none did lead me to a solution
public int getUserIDfromDBcoolpag(String inputUsername){
System.out.println("getUserIDfromDBcoolpag called");
int playerID = 0;
try {
SQLConnection.getInstance().init(DATABASE_HOST, DATABASE_PORT, DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD);
Connection connection = SQLConnection.getInstance().getConnection();
try
{
String getPlayerID = "SELECT coolpag.player.id as cid FROM coolpag.player WHERE username=" +inputUsername;
PreparedStatement statement = connection.prepareStatement(getPlayerID);
try
{
ResultSet res = statement.executeQuery();
try
{
while (res.next())
{
playerID = res.getInt("cid");
}
// System.out.println("LOG: output operation finished");
}
finally
{
res.close();
}
}
finally
{
statement.close();
}
}
finally
{
}
boolean isAlive = SQLConnection.getInstance().getConnection().isClosed();
if(isAlive){
System.out.println("Connection is not yet closed");
}
} catch (NullPointerException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return playerID;
}