1. The client passes the data in JSON format to the server, and now provides a HASHMAP to JSON format data method
Public StaticString Hashjson (hashmap<string, string>map) {String String= "[{"; for(iterator<entry<string, string>> it =Map.entryset (). iterator (); It.hasnext ();) {Entry<string, string> e = (entry<string, string>) It.next (); String+ = "'" + e.getkey () + "':"; String+ = "'" + e.getvalue () + "',"; } string= string.substring (0, String.LastIndexOf (",")); String+= "}]"; returnstring; }
2. Get a specific date format method
Public classTimesimple { Public StaticString gettimesimple () {SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyymmddhhmmsssss"); returnSdf.format (NewDate ()); } Public StaticString getdatasimple () {SimpleDateFormat SDF=NewSimpleDateFormat ("Yyyy-mm-dd"); returnSdf.format (NewDate ()); }}
3. Connect the Database method
Public Staticstring Query (String database, String tablename, String coulmn) {Connection conn=NULL; String SQL; intCinemaid = 0; Try{class.forname ("Com.mysql.jdbc.Driver"); System.out.println ("Load MySQL driver successfully"); Conn=(Connection) drivermanager.getconnection (URL); Statement stmt=(Statement) conn.createstatement (); SQL= "SELECT * from" + database + "where" + tablename + "= '" + coulmn + "'"; SYSTEM.OUT.PRINTLN (SQL); ResultSet RS=(ResultSet) stmt.executequery (SQL); if(Rs.next ()) {Cinemaid= Rs.getint ("id"); } Else{System.out.println ("No Cinema ID is queried"); } } Catch(Exception e) {System.out.println ("MySQL Operation Error"); E.printstacktrace (); }finally { Try{conn.close (); } Catch(SQLException e) {e.printstacktrace (); }} System.out.println (Cinemaid+ ""); returnstring.valueof (Cinemaid); }
HttpClient + TestNG Interface Automatic Test fourth chapter