Newer
Older
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import db.Connect;
/**
*
* @author sqlitetutorial.net
*/
public class DbStart {
/**
* Connect to a sample database
*/
//static Connection conn = null;
/*
public static void connect() {
try {
// db parameters
String url = "jdbc:sqlite:DBPissirDomain.db";
create a connection to the database
conn = DriverManager.getConnection(url);
System.out.println("Connection to SQLite has been established.");
System.out.println("OIOI");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}
*/
public static ArrayList<Dominio> domainsGet() throws SQLException {
//connect();
/**
* Connect to a sample database
*/
//public static Connection conn = null;
Connection conn = null;
try {
// db parameters
String url = "jdbc:sqlite:DBPissirDomain.db";
// create a connection to the database
conn = DriverManager.getConnection(url);
System.out.println("Connection to SQLite has been established.");
/*
String sql= "SELECT * FROM Utenti";
Statement statement =conn.createStatement();
ResultSet result =statement.executeQuery(sql);
while (result.next()) {
String name=result.getString("User");
String desc=result.getString("Desc");
System.out.println(name+desc);
}*/
String sql= "SELECT * FROM Domini";
Statement statement =conn.createStatement();
ResultSet result =statement.executeQuery(sql);
System.out.println("57");
ArrayList<Dominio> res=new ArrayList <Dominio>();
while (result.next()) {
System.out.println("60");
String dom=result.getString("Domain");
String desc=result.getString("Desc");
//String users=result.getString("Users");
ArrayList<String> users = new ArrayList<String>(Arrays.asList(result.getString("Users").split(",")));
ArrayList<String> reso = new ArrayList<String>(Arrays.asList(result.getString("Resources").split(",")));
//String reso=result.getString("Resources");
String state=result.getString("State");
ArrayList<String> serv = new ArrayList<String>(Arrays.asList(result.getString("Services").split(",")));
//String serv=result.getString("Services");
Dominio d=new Dominio(dom,desc,users,reso,state,serv);
res.add(d);
System.out.println("74");
}
return res;
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
return null;
}
public static Dominio getDom(String dm) throws SQLException {
//connect();
//Statement statement =conn.createStatement();
Connection conn = null;
try {
// db parameters
String url = "jdbc:sqlite:DBPissirDomain.db";
// create a connection to the database
conn = DriverManager.getConnection(url);
System.out.println("Connection to SQLite has been established.");
/*
String sql= "SELECT * FROM Utenti";
Statement statement =conn.createStatement();
ResultSet result =statement.executeQuery(sql);
while (result.next()) {
String name=result.getString("User");
String desc=result.getString("Desc");
System.out.println(name+desc);
}*/
PreparedStatement prepared = conn.prepareStatement("SELECT * FROM Domini WHERE Domain = ?");
prepared.setString(1, dm);
ResultSet result = prepared.executeQuery();
//String sql= "SELECT * FROM Domini WHERE Domain = ?";
//ResultSet result =statement.executeQuery(sql);
//Dominio res=new Dominio();
while (result.next()) {
String dom=result.getString("Domain");
String desc=result.getString("Desc");
//String users=result.getString("Users");
ArrayList<String> users = new ArrayList<String>(Arrays.asList(result.getString("Users").split(",")));
ArrayList<String> reso = new ArrayList<String>(Arrays.asList(result.getString("Resources").split(",")));
//String reso=result.getString("Resources");
String state=result.getString("State");
ArrayList<String> serv = new ArrayList<String>(Arrays.asList(result.getString("Services").split(",")));
//String serv=result.getString("Services");
Dominio d=new Dominio(dom,desc,users,reso,state,serv);
//res.add(d);
return d;
}
return null;
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
return null;
}
/**
* @param args the command line arguments
*/
//public static void main(String[] args) {
// connect();
//}
}