Guest User

Untitled

a guest
Mar 5th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. String cname = request.getParameter("cname");
  2. try{
  3. // Register JDBC driver
  4. Class.forName("com.mysql.jdbc.Driver");
  5.  
  6. // Open a connection
  7. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/infoshare", "root", "");
  8.  
  9. // Execute SQL query
  10. Statement stmt = conn.createStatement();
  11.  
  12. String sql;
  13. sql = "INSERT INTO catagory(Catagory_name) VALUES("+cname+")";
  14.  
  15. //ResultSet rs = stmt.executeQuery(sql);
  16. //out.print(cname);
  17.  
  18. stmt.executeUpdate(sql);
  19. out.print("<h1>Hello</h1>");
  20.  
  21. // Clean-up environment
  22. //rs.close();
  23. stmt.close();
  24. conn.close();
  25. }catch(SQLException se){
  26. //Handle errors for JDBC
  27. se.printStackTrace();
  28. }catch(Exception e){
  29. //Handle errors for Class.forName
  30. e.printStackTrace();
  31. }
Add Comment
Please, Sign In to add comment