1010import  java .sql .SQLException ;
1111import  java .sql .Statement ;
1212
13+ import  java .text .DateFormat ;
14+ import  java .text .SimpleDateFormat ;
15+ 
16+ import  java .util .Date ;
1317import  java .util .Enumeration ;
1418import  java .util .Properties ;
1519
@@ -25,11 +29,22 @@ public class Program {
2529
2630	private  static  final  String  DB_TABLE  = "animals" ;
2731
32+ 	private  static  final  String  DB_UPDATE_COLUMN  = "remark" ;
33+ 
2834	private  static  final  String  DB_COLUMN  = "id" ;
2935	private  static  final  int  DB_COLUMN_VALUE  = 1 ;
3036
3137	private  static  final  String  DB_TOTAL_NAME  = "total" ;
3238
39+ 	private  static  String  getNow ()
40+ 	{
41+ 		Date  date  = new  Date ();
42+ 		DateFormat  dateFormat  = new  SimpleDateFormat ("d.M.yyyy H:mm:ss" );
43+ 		String  retValue  = dateFormat .format (date );
44+ 
45+ 		return  retValue ;
46+ 	}
47+ 
3348	public  static  void  main (String [] args ) {
3449		try  {
3550			Class .forName (DB_DRIVER );
@@ -47,6 +62,16 @@ public static void main(String[] args) {
4762				out .println (key  + " : "  + value );
4863			}
4964
65+ 			// UPDATE statement 
66+ 			String  new_comment  = "Java "  + getNow ();
67+ 
68+ 			PreparedStatement  stm0  = conn .prepareStatement ("update "  + DB_TABLE  + " set "  + DB_UPDATE_COLUMN  + "=? where "  + DB_COLUMN  + "!=?" );
69+ 			stm0 .setString (1 , new_comment );
70+ 			stm0 .setInt (2 , DB_COLUMN_VALUE );
71+ 			int  updatedRows0  = stm0 .executeUpdate ();
72+ 			out .println ("Total updated rows: "  + updatedRows0 );
73+ 			out .println ();
74+ 
5075			// Full SELECT statement 
5176			Statement  stm1  = conn .createStatement ();
5277			ResultSet  rs1  = stm1 .executeQuery ("select * from "  + DB_TABLE );
0 commit comments