Guest User

No reponse of restful service after deploying

a guest
Mar 17th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. //AlertDao.java the service to insert country name in country table
  2.  
  3. public class AlertDao {
  4. public boolean insertCountry(Connection connection, String countryName) {
  5.  
  6. PreparedStatement ps;
  7. boolean insertStatus = false;
  8.  
  9. try {
  10. ps = connection.prepareStatement("SELECT COUNTRY_ID FROM COUNTRY WHERE COUNTRY_NAME = ?");
  11. ps.setString(1, countryName);
  12. ResultSet rs = ps.executeQuery();
  13. if (!rs.next()) {
  14. rs.close();
  15. ps.close();
  16. ps = connection.prepareStatement("INSERT INTO COUNTRY (COUNTRY_NAME) VALUES (?) ");
  17. ps.setString(1, countryName);
  18. int records = ps.executeUpdate();
  19. if (records > 0) {
  20. insertStatus = true;
  21. }
  22.  
  23. }
  24.  
  25. ps.close();
  26. connection.commit();
  27. connection.close();
  28.  
  29. } catch (Exception e) {
  30. System.out.println(e);
  31. }
  32.  
  33. return insertStatus;
  34.  
  35. }
  36.  
  37. }
  38. /*************************************************************************************/
  39. //Database.java for connection with mySQL
  40. public class Database {
  41.  
  42.  
  43. public Connection Get_Connection() throws Exception
  44. {
  45. try
  46. {
  47. String connectionURL = "jdbc:mysql://localhost:3306/atm";
  48. Connection connection = null;
  49. Class.forName("com.mysql.jdbc.Driver").newInstance();
  50. connection = DriverManager.getConnection(connectionURL, "root", "admin");
  51. return connection;
  52. }
  53. catch (SQLException e)
  54. {
  55. throw e;
  56. }
  57. catch (Exception e)
  58. {
  59. throw e;
  60. }
  61. }
  62.  
  63.  
  64. }
  65. /**************************************************************************************************/
  66.  
  67. //AtmService.java to call service to insert country name in mysql db
  68. @Path("/WebService")
  69. public class AtmService {
  70. @PUT
  71. @Path("/insertCountry")
  72. //@PathParam("connection")
  73. //@PathParam("countryName")
  74.  
  75. public int insertCountry(String countryName) {
  76. System.out.println("Inside checkCredentials");
  77. int result = 3;
  78. try {
  79. Database database = new Database();
  80. Connection connection = database.Get_Connection();
  81.  
  82. AlertDao n = new AlertDao();
  83. boolean b = n.insertCountry(connection, countryName);
  84.  
  85. Gson gson = new Gson();
  86. System.out.println(gson.toJson(b));
  87.  
  88. result = 1;
  89.  
  90. } catch (Exception e) {
  91. System.out.println(e);
  92. }
  93. System.out.println(result);
  94. return result;
  95.  
  96. }
  97.  
  98. }
  99. /*******************************************/
  100. URL which I am passing
  101. http://localhost:8080/DemoJavaAngular/REST/WebService/insertCountry/"INDIA"
  102.  
  103. DemoJavaAngular- Project Name
  104. REST - URL pattern
  105. WebService/insertContry - Path name
  106. "INDIA" - parameter
  107.  
  108. My question after passing this URL I am getting no response neither the country name is added nor any kind of exception or erros are genrated.
Add Comment
Please, Sign In to add comment