jsp - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; -
hey guys have error message, connect between server , client , select data mysql server , insert in mysql client insert statement not happen
com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: have error in sql syntax; check manual corresponds mysql server version right syntax use near ''context'.login values (1,'alamal','alamal','alamal','alamal)' @ line 1
and code..
<% try{ connection con1; connection con2; class.forname("com.mysql.jdbc.driver"); con1=(connection)drivermanager.getconnection("jdbc:mysql://192.168.101.1:3306/context","hospital","0000"); preparedstatement ps1=(preparedstatement)con1.preparestatement("select * hospital"); string str; resultset rs1=ps1.executequery(); while(rs1.next()){ con2=(connection)drivermanager.getconnection("jdbc:mysql://localhost:3306/context","root",""); con2.setautocommit(true); con2.createstatement(); int id=rs1.getint("id"); string username=rs1.getstring("username"); string password=rs1.getstring("password"); string hname=rs1.getstring("hospitalname"); string haddress=rs1.getstring("hospitaladdress"); preparedstatement state= (preparedstatement)con2.preparestatement("insert 'context'.'login' values(?,?,?,?,?);"); state.setint(1, id); state.setstring(2, username); state.setstring(3, password); state.setstring(4, hname); state.setstring(5, haddress); state.executeupdate(); con2.close(); } con1.close(); } catch(exception ex){ out.print(ex); } %>
you have silly mistake in writing sql query work fine.
<% try{ connection con1; connection con2; class.forname("com.mysql.jdbc.driver"); con1=(connection)drivermanager.getconnection("jdbc:mysql://192.168.101.1:3306/context","hospital","0000"); preparedstatement ps1=(preparedstatement)con1.preparestatement("select * hospital"); string str; resultset rs1=ps1.executequery(); while(rs1.next()){ con2=(connection)drivermanager.getconnection("jdbc:mysql://localhost:3306/context","root",""); con2.setautocommit(true); con2.createstatement(); int id=rs1.getint("id"); string username=rs1.getstring("username"); string password=rs1.getstring("password"); string hname=rs1.getstring("hospitalname"); string haddress=rs1.getstring("hospitaladdress"); preparedstatement state= (preparedstatement)con2.preparestatement("insert `context`.`login` values(?,?,?,?,?);"); state.setint(1, id); state.setstring(2, username); state.setstring(3, password); state.setstring(4, hname); state.setstring(5, haddress); state.executeupdate(); con2.close(); } con1.close(); } catch(exception ex){ out.print(ex); } %>
Comments
Post a Comment