1
1
package com .jx ;
2
2
3
- import com .jx .db . DataBase ;
4
- import com .jx .db . DataBaseConfig ;
3
+ import com .jx .config . DataBaseConfig ;
4
+ import com .jx .library . DataBase ;
5
5
import com .jx .model .Producto ;
6
- import java .util .LinkedHashMap ;
7
6
import java .sql .ResultSet ;
8
7
import java .sql .SQLException ;
8
+ import java .util .LinkedHashMap ;
9
9
10
10
/**
11
11
*
12
12
* @author Jesus
13
13
*/
14
- public class Demo {
14
+ public class Main {
15
15
16
16
public void select () throws SQLException {
17
17
try (DataBase db = DataBaseConfig .getDataBaseMySQL ()) {
@@ -30,19 +30,19 @@ public void select() throws SQLException {
30
30
}
31
31
}
32
32
33
- public int count () throws SQLException {
33
+ public long count () throws SQLException {
34
34
try (DataBase db = DataBaseConfig .getDataBaseMySQL ()) {
35
35
return db .count ("producto" , null );
36
36
}
37
37
}
38
38
39
- public int insert (Producto p ) throws SQLException {
39
+ public long insert (Producto p ) throws SQLException {
40
40
try (DataBase db = DataBaseConfig .getDataBaseMySQL ()) {
41
41
LinkedHashMap <String , Object > values = new LinkedHashMap <>();
42
42
values .put ("codigo" , p .getCodigo ());
43
43
values .put ("nombre" , p .getNombre ());
44
44
45
- int id_insertado = db .insert ("producto" , values );
45
+ long id_insertado = db .insert ("producto" , values );
46
46
p .setId (id_insertado );
47
47
return id_insertado ;
48
48
}
@@ -58,32 +58,35 @@ public int update(Producto p) throws SQLException {
58
58
}
59
59
}
60
60
61
- public int delete (int id ) throws SQLException {
61
+ public int delete (long id ) throws SQLException {
62
62
try (DataBase db = DataBaseConfig .getDataBaseMySQL ()) {
63
63
return db .delete ("producto" , "id = ?" , id );
64
64
}
65
65
}
66
66
67
- public static void main (String ... args ) throws SQLException {
68
- Demo demo = new Demo ();
69
-
70
- Producto p = new Producto ();
71
- p .setCodigo ("PC-" + System .currentTimeMillis ());
72
- p .setNombre ("PC" );
73
-
74
- demo .insert (p );
75
- System .out .println ("insert:" + p );
76
-
77
-
78
- p .setCodigo ("PC-" + System .currentTimeMillis ());
79
-
80
- demo .update (p );
81
- System .out .println ("update:" + p );
82
-
83
- demo .delete (4 );
84
-
85
- demo .select ();
86
-
87
- System .out .println ("count:" + demo .count ());
67
+ public static void main (String ... args ) {
68
+ Main demo = new Main ();
69
+
70
+ try {
71
+ System .out .println ("count:" + demo .count ());
72
+
73
+ Producto p = new Producto ();
74
+ p .setCodigo ("PC-" + System .currentTimeMillis ());
75
+ p .setNombre ("PC" );
76
+ demo .insert (p );
77
+ System .out .println ("insert:" + p );
78
+
79
+ p .setCodigo ("PC-" + System .currentTimeMillis ());
80
+ demo .update (p );
81
+ System .out .println ("update:" + p );
82
+
83
+ demo .delete (4 );
84
+
85
+ demo .select ();
86
+
87
+ System .out .println ("count:" + demo .count ());
88
+ } catch (SQLException e ) {
89
+ System .out .println (e .getMessage ());
90
+ }
88
91
}
89
92
}
0 commit comments