File tree 2 files changed +21
-0
lines changed
demo/src/main/java/com/example/database
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -67,4 +67,14 @@ public Person getById(int id) throws SQLException{
67
67
68
68
return null ;
69
69
}
70
+
71
+ public void update (Person person ) throws SQLException {
72
+ Statement statement = connetion .createStatement ();
73
+
74
+ /* UPDATE table SET column = value [, ...] [WHERE condition] */
75
+
76
+ statement .executeUpdate ("update person set name = '" + person .getName () + "' where id = " + person .getId ());
77
+
78
+ statement .close ();
79
+ }
70
80
}
Original file line number Diff line number Diff line change @@ -33,6 +33,15 @@ public static void main(String[] args) throws IOException{
33
33
// Delete data
34
34
/* personDao.delete(2); */
35
35
36
+ Person person3 = new Person ();
37
+
38
+ person3 .setId (3 );
39
+ person3 .setName ("Carlos" );
40
+
41
+ personDao .update (person3 );
42
+
43
+
44
+
36
45
// Get all data
37
46
List <Person > persons = personDao .getAll ();
38
47
@@ -45,6 +54,8 @@ public static void main(String[] args) throws IOException{
45
54
/* Person person2 = personDao.getById(2);
46
55
System.out.println(person2); */
47
56
57
+
58
+
48
59
} catch (SQLException e ) {
49
60
// if the error message is "out of memory",
50
61
// it probably means no database file is found
You can’t perform that action at this time.
0 commit comments