I'm trying to query MySQL database
statement = conn.createStatement();
String sql = "select * from file_post where gas_key='"+commun+"'";
fp =statement.executeQuery(sql);
where commun
is
String commun= (String) session.getAttribute("commun");
I'm getting exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'bro' in 'where clause'
bro
is the value of commun.
I also tried PreparedStatement
, but that also gave me the same exception.
But when I make a query in MySQL command line:
select * from file_post where gas_key='bro';
It's perfect there and returns the exact data.
I can't figure out why it is giving me the exception when using the same query in a Java class.