Skip to content

Commit b909fcd

Browse files
author
JesusBetaX
committed
init 8
1 parent 82bb7d4 commit b909fcd

File tree

10 files changed

+649
-115
lines changed

10 files changed

+649
-115
lines changed

lib/sqljdbc4.jar

571 KB
Binary file not shown.

nbproject/project.properties

+15-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ dist.jar=${dist.dir}/Jdbc.jar
2929
dist.javadoc.dir=${dist.dir}/javadoc
3030
endorsed.classpath=
3131
excludes=
32+
file.reference.sqljdbc4.jar=lib/sqljdbc4.jar
3233
includes=**
34+
jar.archive.disabled=${jnlp.enabled}
3335
jar.compress=false
36+
jar.index=${jnlp.enabled}
3437
javac.classpath=\
35-
${libs.MySQLDriver.classpath}
38+
${libs.MySQLDriver.classpath}:\
39+
${file.reference.sqljdbc4.jar}
3640
# Space-separated list of extra javac options
3741
javac.compilerargs=
3842
javac.deprecation=false
@@ -57,7 +61,16 @@ javadoc.splitindex=true
5761
javadoc.use=true
5862
javadoc.version=false
5963
javadoc.windowtitle=
60-
main.class=
64+
jnlp.codebase.type=no.codebase
65+
jnlp.descriptor=application
66+
jnlp.enabled=false
67+
jnlp.mixed.code=default
68+
jnlp.offline-allowed=false
69+
jnlp.signed=false
70+
jnlp.signing=
71+
jnlp.signing.alias=
72+
jnlp.signing.keystore=
73+
main.class=com.jx.Main
6174
manifest.file=manifest.mf
6275
meta.inf.dir=${src.dir}/META-INF
6376
mkdist.disabled=false
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.jx;
22

3-
import com.jx.db.DataBase;
4-
import com.jx.db.DataBaseConfig;
3+
import com.jx.config.DataBaseConfig;
4+
import com.jx.library.DataBase;
55
import com.jx.model.Producto;
6-
import java.util.LinkedHashMap;
76
import java.sql.ResultSet;
87
import java.sql.SQLException;
8+
import java.util.LinkedHashMap;
99

1010
/**
1111
*
1212
* @author Jesus
1313
*/
14-
public class Demo {
14+
public class Main {
1515

1616
public void select() throws SQLException {
1717
try (DataBase db = DataBaseConfig.getDataBaseMySQL()) {
@@ -30,19 +30,19 @@ public void select() throws SQLException {
3030
}
3131
}
3232

33-
public int count() throws SQLException {
33+
public long count() throws SQLException {
3434
try (DataBase db = DataBaseConfig.getDataBaseMySQL()) {
3535
return db.count("producto", null);
3636
}
3737
}
3838

39-
public int insert(Producto p) throws SQLException {
39+
public long insert(Producto p) throws SQLException {
4040
try (DataBase db = DataBaseConfig.getDataBaseMySQL()) {
4141
LinkedHashMap<String, Object> values = new LinkedHashMap<>();
4242
values.put("codigo", p.getCodigo());
4343
values.put("nombre", p.getNombre());
4444

45-
int id_insertado = db.insert("producto", values);
45+
long id_insertado = db.insert("producto", values);
4646
p.setId(id_insertado);
4747
return id_insertado;
4848
}
@@ -58,32 +58,35 @@ public int update(Producto p) throws SQLException {
5858
}
5959
}
6060

61-
public int delete(int id) throws SQLException {
61+
public int delete(long id) throws SQLException {
6262
try (DataBase db = DataBaseConfig.getDataBaseMySQL()) {
6363
return db.delete("producto", "id = ?", id);
6464
}
6565
}
6666

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+
}
8891
}
8992
}

src/com/jx/config/DataBaseConfig.java

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.jx.config;
2+
3+
import com.jx.library.DataBase;
4+
5+
/**
6+
*
7+
* @author Jesus
8+
*/
9+
public final class DataBaseConfig {
10+
11+
private static DataBase mysql;
12+
private static DataBase sqlserver;
13+
14+
private DataBaseConfig() {
15+
}
16+
17+
public static DataBase getDataBaseMySQL() {
18+
if (mysql == null) {
19+
mysql = new DataBase();
20+
// Ejemplo con base de datos MySQL
21+
mysql.setDriverClassName("com.mysql.jdbc.Driver");
22+
mysql.setUrl("jdbc:mysql://localhost:3306/punto_venta");
23+
mysql.setUsername(/*"usuario"*/"root");
24+
mysql.setPassword(/*"password"*/"");
25+
mysql.setDebug(Boolean.TRUE);
26+
}
27+
return mysql;
28+
}
29+
30+
public static DataBase getDataBaseSQLServer() {
31+
if (sqlserver == null) {
32+
sqlserver = new DataBase();
33+
// Ejemplo con base de datos SqlServer
34+
sqlserver.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
35+
sqlserver.setUrl("jdbc:sqlserver://localhost;databaseName=dataBase;");
36+
sqlserver.setUsername(/*"usuario"*/"sa");
37+
sqlserver.setPassword(/*"password"*/"123456");
38+
}
39+
return sqlserver;
40+
}
41+
}
File renamed without changes.

src/com/jx/db/DataBaseConfig.java

-25
This file was deleted.

0 commit comments

Comments
 (0)