Update a linear table

Source: Internet
Author: User
Tags psql

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 ();
}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.