-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestConnection.java
More file actions
39 lines (26 loc) · 814 Bytes
/
Copy pathtestConnection.java
File metadata and controls
39 lines (26 loc) · 814 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
package jdbcPrueba;
import java.sql.*;
public class testConnection{
public static void main(String[] args) throws SQLException {
Connection myConn = null;
Statement myStatm = null;
ResultSet myRes = null;
try {
//1. Conexion a base de datos
myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/proyecto", "platzi", "platzi");
System.out.println("Genial nos conectamos");
//2. Objeto statement
myStatm = myConn.createStatement();
//3. Ejecutar consulta SQL
myRes = myStatm.executeQuery("select * from clientes");
//4.Procesarlos
while(myRes.next()) {
System.out.println(myRes.getString("primer_nombre"));
}
}
catch (Exception exc) {
exc.printStackTrace();
System.out.println("Algo salio mal):");
}
}
}