-
Notifications
You must be signed in to change notification settings - Fork 0
/
Java(DriverManager)
44 lines (29 loc) · 943 Bytes
/
Java(DriverManager)
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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class banco_de_dados {
public static void main(String[]args){
try {//Usamos try catch porque estamos usando o static void
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
Connection conexao = DriverManager.getConnection("jdbc:mysql://localhost/Loja","root","123456");
//Criar o comando para executar o sql
Statement comando = null;
comando = conexao.createStatement();
String sql = "select * from inf_loja;";
ResultSet rsLojas = comando.executeQuery(sql);
while (rsLojas.next()){
System.out.println(
rsLojas.getInt("id_loja") + ":"+
rsLojas.getString("nome"));
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}