-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattleShip.java
58 lines (53 loc) · 1.63 KB
/
BattleShip.java
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
import java.sql.*;
//public class BattleShip {
public class BattleShip {
//static final String CONN_URL = "jdbc:oracle:thin:@ensioracle1.imag.fr:1521:ensioracle1";
static final String CONN_URL = "jdbc:oracle:thin:@ensibm.imag.fr:1521:ensi2";
static final String USER = "guys"; // A remplacer pour votre compte
static final String PASSWD = "guys";
static final String STMT = "select * from emp";
public BattleShip() {
try {
// Enregistrement du driver Oracle
System.out.print("Loading Oracle driver... ");
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
System.out.println("loaded");
// Etablissement de la connection
System.out.print("Connecting to the database... ");
Connection conn = DriverManager.getConnection(CONN_URL, USER, PASSWD);
System.out.println("connected");
// Creation de la requete
Statement stmt = conn.createStatement();
// Execution de la requete
ResultSet rset = stmt.executeQuery(STMT);
// Affichage du resultat
System.out.println("Results:");
dumpResultSet(rset);
System.out.println();
// Fermeture
rset.close();
stmt.close();
conn.close();
} catch (SQLException e) {
System.err.println("failed");
e.printStackTrace(System.err);
}
}
private void dumpResultSet(ResultSet rset) throws SQLException {
ResultSetMetaData rsetmd = rset.getMetaData();
int i = rsetmd.getColumnCount();
for (int k=1;k<=i;k++)
System.out.print(rsetmd.getColumnName(k) + "\t");
System.out.println();
while (rset.next()) {
for (int j = 1; j <= i; j++) {
System.out.print(rset.getString(j) + "\t");
}
System.out.println();
}
}
public static void main(String args[]) {
new BattleShip();
}
}
//}