tag:blogger.com,1999:blog-5208088681305957591.post4308193482386747752..comments2023-12-21T01:04:27.555-05:00Comments on onlyxcodes: How to Produce and Consume Restful Webservice in JavaHamid Shaikhhttp://www.blogger.com/profile/11249349085848207703noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5208088681305957591.post-65378003015696457762020-11-15T05:15:00.914-05:002020-11-15T05:15:00.914-05:00No, my code working perfectly, your code few diffe...No, my code working perfectly, your code few different.<br /><br />After executing query, Look I retrieving all record from table with proper assignment type int and string.<br /><br />public User getUserId(int id)<br />{<br /> User user = new User();<br /> try<br /> {<br /> pstmt=con.prepareStatement("SELECT * FROM tbl_user WHERE id=? ");<br /> ResultSet rs=pstmt.executeQuery();<br /> if(rs.next())<br /> {<br /> user.setId(rs.getInt("id"));<br /> user.setUsername(rs.getString("username"));<br /> user.setOwner(rs.getString("owner"));<br /> }<br /> }<br /> catch(Exception e)<br /> {<br /> System.out.println(e);<br /> }<br /> <br /> return user;<br />}<br />Hamid Shaikhhttps://www.blogger.com/profile/11249349085848207703noreply@blogger.comtag:blogger.com,1999:blog-5208088681305957591.post-63614073278840742722020-11-14T12:29:48.884-05:002020-11-14T12:29:48.884-05:00I found a bug in getUserId(int id) method of class...I found a bug in getUserId(int id) method of class UserRepository. Please add "pstmt.setInt(1, id);" as shown below to fix that issue. <br />public User getUserId(int id) {<br /> <br /> User user = new User(); <br /> <br /> try {<br /> pstmt = con.prepareStatement("SELECT * FROM tbl_user WHERE id=?");<br /> pstmt.setInt(1, id);Anonymoushttps://www.blogger.com/profile/16241906514421359960noreply@blogger.com