java - How to change table name of from clause in PreparedStatement -
hi have small problem, how switch tables results from?? code below not working.however should give idea of trying do. help
string typelogin=null; if(xx){ typelogin="users_table"; }else{ typelogin="admin_table"; } string sqlstr = "select * "+typelogin+" username=? , userpassword=?"; preparedstatement stmt = conn.preparestatement(sqlstr);
the full code:
statement stmt = conn.createstatement(); string sqlstr = "select * "+typelogin+" username=? , userpassword=?"; preparedstatement pstmt=conn.preparestatement(sqlstr); pstmt.setstring(1,user); pstmt.setstring(2,password); //step 6 process result resultset rs = pstmt.executequery();
the error getting:
com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'fromspmovy_admin username='abc' , userpassword='abc'' @ line 1
answer[solved]:
forgot put white space
from " + typelogin + "
from error message: 'fromspmovy_admin ...
looks missed whitespace between from
, table name. make sure you're doing in right way in methods (note in current example won't happen).
Comments
Post a Comment