using a servlet to add values to database

I'm new to servlet use, so please forgive my ignorance. I developed a class that inserts values to a table in a DB and I'd like to use the method `InsertValue` in a servlet, so that the values entered in the form would be inserted directly in the table. If, somehow that helps, here's the code of the `InsertValue` method : public class InsetValue { { try { Statement stmt; Connectionx cx = new Connectionx(); Connection con= cx.Connexion("com.mysql.jdbc.Driver","jdbc:mysql://localhost/jiradb4.3","root","root"); stmt = (Statement) con.createStatement(); int ID = 10200; String s = new String("PAYROLL"); String url = new String(""); String lead = new String ("amira.jouida"); String desc = new String ("projet payroll"); String key = new String ("PROLL"); int pcount = 0; int asstype = 2; int avatar = 10011; stmt.executeUpdate("INSERT INTO project " +" VALUES ('"+ ID +"','"+ s +"','"+ url +"','"+ lead +"','"+ desc +"','"+ key +"','"+ pcount +"','"+ asstype +"','"+ avatar +"');"); stmt.close(); System.out.println ("Done"); } catch (SQLException ex) { } } } This works perfectly for me. I red some documents about `servlets`, but I’m still wondering how to handle this issue. Thanks for your help. Regards

以上就是using a servlet to add values to database的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏