Advertisement
Guest User

Untitled

a guest
Feb 28th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. public class publishStory extends HttpServlet{
  2. protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
  3. PreparedStatement pstmt = null;
  4. Connection cn = null;
  5. ResultSet rs = null;
  6. boolean flag = false;
  7. PrintWriter out = null;
  8. try{
  9. System.out.println("CALLING THE METHOD");
  10. Class.forName("com.mysql.jdbc.Driver");
  11. cn = DriverManager.getConnection("jdbc:mysql://localhost/storyboard","root","");
  12.  
  13. BufferedReader reader = request.getReader();
  14. JSONParser parser = new JSONParser();
  15. JSONObject juser = null;
  16.  
  17. juser = (JSONObject)parser.parse(reader);
  18.  
  19. String welcomeStoryTitle = (String)juser.get("welcomeStoryTitle");
  20. String welcomeStoryWords = (String)juser.get("welcomeStoryWords");
  21.  
  22. String query = "INSERT INTO stories (storytitle, storytext) VALUES (?,?)";
  23. pstmt = cn.prepareStatement(query);
  24. pstmt.setString(1, welcomeStoryTitle);
  25. pstmt.setString(2, welcomeStoryWords);
  26. int i = pstmt.executeUpdate();
  27. if(i>0)
  28. System.out.println(welcomeStoryTitle=" : "+welcomeStoryWords);
  29. else
  30. System.out.println("No data inserted");
  31. }
  32. catch(Exception e){
  33. e.printStackTrace();
  34. }
  35. }
  36.  
  37. app.controller('welcomeStoryPublishCtrl', ['$log','$http',function($log,$http){
  38. this.publishGroup = function(wsPublish){
  39. $http({
  40. method:'POST',
  41. url: 'http://localhost:9090/Writer/publishStory',
  42. header: {'Content-Type':'application/json'},
  43. data: wsPublish
  44. }).success(function(){});
  45. };
  46. }]);
  47.  
  48. juser = (JSONObject)parser.parse(reader);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement