Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 2.22 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Java - Remove unprintable character from string
  2. ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
  3. postParameters.add(new BasicNameValuePair("nric",nric));
  4. response = CustomHttpClient.executeHttpPost("http://172.27.176.181:8080/SRD/SaveLocation", postParameters);
  5.        
  6. String nric = request.getParameter("nric");
  7.     nric = nric.replace("n", "");
  8. User elder = new User();
  9.     elder.setNric(nric);
  10.     try {
  11.         if(elder.retrieveUserWithNric())
  12.         {
  13.        
  14. public boolean retrieveUserWithNric() throws SQLException
  15. {
  16.     boolean success = false;
  17.     ResultSet rs = null;
  18.     try {
  19.         Context ctx = new InitialContext();
  20.         ds = (DataSource)ctx.lookup("java:comp/env/jdbc/srd");
  21.       } catch (NamingException e) {
  22.           System.out.println("User: Naming Exception");
  23.         e.printStackTrace();
  24.       }
  25.     Connection conn = ds.getConnection();
  26.  
  27.     PreparedStatement pstmt = null;
  28.     String dbQuery = "SELECT * FROM User WHERE nric = ?";
  29.     System.out.println("retrieveUserwithNric nric is "+nric);
  30.     try {
  31.         pstmt = conn.prepareStatement(dbQuery);
  32.         pstmt.setString(1, nric);
  33.         rs = pstmt.executeQuery();
  34.     } catch (SQLException e1) {
  35.         // TODO Auto-generated catch block
  36.         e1.printStackTrace();
  37.     }
  38.     try {
  39.         if (rs.next()) {
  40.             id = rs.getInt("id");
  41.             nric = rs.getString("nric");
  42.             password = rs.getString("password");
  43.             salt = rs.getString("salt");
  44.             name = rs.getString("name");
  45.             mobileNo = rs.getInt("mobile_no");
  46.             address = rs.getString("address");
  47.             postal = rs.getInt("postal_code");
  48.             relativeElderly = rs.getString("relative_elderly");
  49.             role = rs.getString("role");
  50.             organization = rs.getString("organization");
  51.             elderlyList = rs.getString("elderly_list");
  52.             // image = rs.getBlob("image");
  53.             success = true;
  54.         }
  55.         else
  56.         {
  57.             System.out.println("rs does not have next");
  58.         }
  59.     } catch (Exception e) {
  60.         e.printStackTrace();
  61.     }
  62.     System.out.println("name is "+name);
  63.     System.out.println("role is "+role);
  64.     conn.close();
  65.     return success;
  66. }
  67.        
  68. WHERE nric = 'S3456789A'