I wrote one last time, but I still felt it was okay. Now it's quite uncomfortable.
When I used JDBC to write Dao, I thought it was okay. I don't know what everyone thinks...
Upload an object to perform the update operation. For the specific content in the "Ten" period, you only need to use the identification column to perform the update operation. .. dynamic structure of the update statement
Public void updatearard (award Award) throws sqlexception ...{
String Teram = award. getteram ();
Java. Text. dateformat df = new java. Text. simpledateformat ("yyyy-mm-dd ");
Date time = NULL;
Try ...{
Time = DF. parse (award. gettime ());
} Catch (parseexception e )...{
E. printstacktrace ();
}
String rs = award. getrs ();
String message = award. getmessage ();
String string1 = award. getstring1 ();
String SQL = "Update award set ";
List list = new arraylist ();
If (Teram! = NULL |! "". Equals (Teram ))...{
SQL + = "Teram = ?, ";
List. Add (Teram );
}
If (time! = NULL |! Time. Equals (null ))...{
SQL + = "time = ?, ";
List. Add (time );
}
If (RS! = NULL |! "". Equals (RS ))...{
SQL + = "rs = ?, ";
List. Add (RS );
}
If (message! = NULL |! "". Equals (Message ))...{
SQL + = "message = ?, ";
List. Add (Message );
}
If (string1! = NULL |! "". Equals (string1 ))...{
SQL + = "string1 = ?, ";
List. Add (string1 );
}
String Psql = SQL. substring (0, SQL. Length ()-1) + "where id =? ";
System. Out. println ("Psql =" + Psql );
Pstmt = con. preparestatement (Psql );
Int I = 1;
For (; I <= List. Size (); I ++ )...{
System. Out. println ("I =" + I );
Pstmt. setobject (I, list. Get (I-1 ));
}
Pstmt. setint (I ++, award. GETID ());
Pstmt.exe cuteupdate ();
Pstmt. Close ();
}