-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJDBCDemo.java
More file actions
39 lines (35 loc) · 952 Bytes
/
Copy pathJDBCDemo.java
File metadata and controls
39 lines (35 loc) · 952 Bytes
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
import java.sql.ResultSet;
public class JDBCDemo {
private void PrintResultSet(ResultSet t) {
try {
int counter = 1;
while (t.next()) {
try {
while (true) {
System.out.print(t.getString(counter));
System.out.print(" ");
counter++;
}
}
catch(Exception e) {}
System.out.print("\n");
counter = 1;
}
} catch (Exception e) {
e.printStackTrace();
}
}
JDBCDemo(){
//connect to the database with the given credentials
Database db = new Database("test", "root", "toor");
//db.UpdateDatabase("insert into Kunden values('Kunde1', 'Nachname' ,'1234','2000-01-01');");
//db.UpdateDatabase("delete from Kunden where Name = 'Kunde1'");
ResultSet s = db.runSQL("select * from Kunden");
PrintResultSet(s);
db.CloseConnection();
}
// remove when using the code in BlueJ, etc.
public static void main(String[] args) {
new JDBCDemo();
}
}