Guest User

Untitled

a guest
Feb 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <%@ page import="java.sql.*" %>
  2. <%
  3. String url = "jdbc:odbc:productDSN";
  4. String username="";
  5. String password="";
  6. Connection conn=null;
  7. String classPath = "sun.jdbc.odbc.JdbcOdbcDriver";
  8. try{
  9. Class.forName(classPath);
  10. conn = DriverManager.getConnection(url,username,password);
  11. }catch(Exception exc){
  12. out.println(exc.toString());
  13. }
  14. Statement stm=null;
  15. string id = request.getParameter("id");
  16. string name = request.getParameter("name");
  17. string model = request.getParameter("model");
  18. string priceS = request.getParameter("price");
  19. string midS = request.getParameter("mid");
  20.  
  21. float price=0;
  22. int mid=0;
  23. try{price = Float.parseFloat(priceS);}catch(Exception exc){}
  24. try{mid = Integer.parseInt(midS);}catch(Exception exc){}
  25. stm= conn.createStatement();
  26. String query = "INSERT INTO product VALUES('"+id+"', '" + name +"', '"+
  27. model + "'," + price +", "+ mid + ")";
  28. try{
  29. stm.executeUpdate(query);
  30. out.println("The data were added to the table successfully!");
  31. }catch(Exception exc){
  32. out.println("Inserting data failed!");
  33. }
  34. stm.close();
  35. conn.close();
  36. %>
  37. <br><br><a href="example5.html">Add more record</a>
Add Comment
Please, Sign In to add comment