java - Quoted string not properly terminated Exception -
i updating password in oracle databse using java servlet
connection con; preparedstatement ps,ps1; resultset rs; try{ class.forname("sun.jdbc.odbc.jdbcodbcdriver"); } catch (classnotfoundexception e) { system.out.println("drivers not found"); } try{ con=drivermanager.getconnection("jdbc:odbc:sharedcryptography", "fyp", "fyp"); }catch(sqlexception e1) { } string query="update tbgroup set gpassword='"+mypassword+"' gname='"+groupnamee+"' , oemail='"+ownerid+"'"; java.sql.statement stmt = con.createstatement(); stmt.executeupdate(query);
but gives java.sql.sqlexception: [oracle][odbc][ora]ora-01756: quoted string not terminated
am doing wrong in it?please help
you should absolutely avoid string concatenation in sql statements. in kind of security , stability problems. problem resolved using prepared statement:
string sql="update tbgroup set gpassword=? gname=? , oemail=?"; preparedstatement ps = con.preparestatement(sql); ps.setstring(1, mypassword); ps.setstring(2, groupname); ps.setstring(3, ownerid); ps.executeupdate();
if this, no "'" or "%" or "_" or " in parameters cause problems. alternatively can try escape characters, why bother - ps method not more robust , easier read, more performant.
for general description of security problems, see: https://www.owasp.org/index.php/sql_injection
Comments
Post a Comment