Java check, display the values registered in the MySQL database

0

I need help I'm doing a game in java and I need all the records and files and etc of the players in my table but I can not connect to the database much less check and display the values

Ps: the Sun.java tutorial from DriverConnector did not help me, could you? PSS: (execute queries and check integers)

    
asked by anonymous 25.07.2014 / 14:13

1 answer

2

This site has everything you need to work with JDBC

Caelum - Databases and JDBC

Example:

// pega a conexão e o Statement
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/seubanco", "user", "password");
PreparedStatement stmt = con.prepareStatement("select * from contatos");

// executa um select
ResultSet rs = stmt.executeQuery();

// itera no ResultSet
while (rs.next()) {
  String nome = rs.getString("nome");
  String email = rs.getString("email")

  System.out.println(nome + " :: " + email);
}

stmt.close();
con.close();
    
25.07.2014 / 14:24