-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL.java
More file actions
41 lines (32 loc) · 1.05 KB
/
SQL.java
File metadata and controls
41 lines (32 loc) · 1.05 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
package JavaDevs;
//@authors Anna Kotsa, Ioanna Kalogeropoulou, Aristi Syriou
import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
public class SQL {
public void Sql(String url, String dbname) throws SQLException {
Connection conn;
Statement stmt;
ResultSet rs;
conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
try {
String Query = "select name, surname, am, telephone from " + dbname + ".SQLDataBase";
rs = stmt.executeQuery(Query);
while (rs.next()) {
String name = rs.getString("name");
String surname = rs.getString("surname");
int am = rs.getInt("AM");
int telephone = rs.getInt("telephone");
System.out.println(name + "\t" + surname +
"\t" + am + "\t" + telephone);
}
} catch (SQLException e ) {
System.out.println("SQLException: ");
System.out.println(e.getMessage());
} finally {
if (stmt != null) { stmt.close(); }
}
}
}