Menu

[r16]: / trunk / src / MyDataAccess.java  Maximize  Restore  History

Download this file

75 lines (50 with data), 1.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.sql.*;
import java.util.ArrayList;
//import javx.sql.*;
public class MyDataAccess {
private static String dbUrl = "jdbc:mysql://localhost/pcmso";
private static String dbClass = "com.mysql.jdbc.Driver";
private static Connection con = null;
private static Statement stmt = null;
//public static ArrayList<String> erros = new ArrayList<String>();
public static void open(){
try {
Class.forName(dbClass);
con = DriverManager.getConnection (dbUrl,"root","uis");
stmt = con.createStatement();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void close(){
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static int ExecuteInsert(String query) throws Exception{
if(query == null) return 0;
try {
stmt.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
ResultSet keyset = stmt.getGeneratedKeys();
if (keyset.next()){
return keyset.getInt(1);
}
}
catch (Exception e) {
System.out.println(query);
e.printStackTrace();
throw new Exception(e.getMessage());
//e.printStackTrace();
}
return -1;
}
/**
* Vai ajudar a calcular a quantidade necessária de inserts no banco de dados..
* @param size
*/
public static int CalculaTamanho(int size){
return 0;
}
}