Connection conn =NULL; Statement stmt=NULL; ResultSet RS=NULL; Try{class.forname ("Com.mysql.jdbc.Driver"); String Dbnmae= "Logall" +params.get ("DbName"); String Dbip= ConfigUtil.pro.get ("Linklogip"). toString (); String Linkcloudsql= "jdbc:mysql://" +dbip+ "/" +Dbnmae; String Linkcloudusername=configutil.pro.get ("Linklogipusername"). toString (); String Linkcloudpassword=configutil.pro.get ("Linklogippassword"). toString (); Conn=DriverManager getconnection (Linkcloudsql,linkcloudusername, Linkclo Udpassword); stmt=conn.createstatement (); PreparedStatement PS=NULL; StringBuffer Buffer=NewStringBuffer (' Select ' id ', ' IDC ', ' flag ', ' cmdstarttime ', ' json ', ' cmdendtime ', ' retvalue ', ' crmid ', case ' fName ' = ' OR ' FName ' are NULL then ' idsid ' ELSE ' fName ' END ' fName ', ' Inserttime ', Timestampdiff (frac_second,cmdstarttime,cmdendtime ) as duration from Log_controlresult WHERE IDC =? and flag in (' Bluetoothcontrol ', ' carcontrolnew ') "); if(Params.get ("ret")! =NULL&& Stringutils.isnoneempty (Params.get ("ret"). ToString ()) {Buffer.append ("and retvalue=?"); } buffer.append ("ORDER BY crmid Desc"); Buffer.append ("LIMIT" +params.get ("StartIndex") + "," +params.get ("PageSize")); PS=(PreparedStatement) conn.preparestatement (buffer.tostring ()); Ps.setstring (1, Params.get ("IDC"). toString ()); if(Params.get ("ret")! =NULL&& Stringutils.isnoneempty (Params.get ("ret"). ToString ()) {ps.setstring (2, Params.get ("ret")). toString ()); } log.info ("Control History sql:" +buffer.tostring ()); RS=Ps.executequery (); while(Rs.next ()) {Controlresult Cresult=NewControlresult (); Cresult.setid (Rs.getlong ("id")); CRESULT.SETIDC (Rs.getstring ("IDC")); Cresult.setflag (Rs.getstring ("Flag")); Cresult.setcmdstarttime (Rs.gettimestamp ("Cmdstarttime")); Cresult.setjson (Rs.getstring ("JSON")); Cresult.setcmdendtime (Rs.gettimestamp ("Cmdendtime")); Cresult.setretvalue (Rs.getstring ("RetValue")); Cresult.setcrmid (Rs.getlong ("Crmid")); Cresult.setfname (Rs.getstring ("FName")); Cresult.setinserttime (Rs.gettimestamp ("Inserttime")); Cresult.setduration (Rs.getint ("duration")); Cresult.setcmdname (Getsendtypenamebyjson (Cresult.getjson ())); Resultlist.add (Cresult); } }
DriverManager Query Database Splicing buffer