Java check, show values recorded in Mysql database

Asked

Viewed 5,030 times

0

I need help I’m making a game in java and I need all records and files and player etc in my table but I can not connect with the database and much less check and display values

Ps: sun.java tutorial from Driverconnector didn’t help me could you? PSS: (run queryes and check integers)

  • I think you could add more information to your question, you’re talking about a desktop game right? ('cause you won’t be able to answer because of reputation I think)

  • Yes However it is completely in java 2D but I just need to create ... int teste1 = SELECT * player_data Where uuid='japkdawdfa-dawdadd' Something like this gives in use a void for this putting between parateses his uuid or whatever else is what I’m stuck

  • I was preparing an answer but since you can answer, I’ll answer here. You use the netbeans? if you have ever considered the possibility of using the Hibernate it is extremely simple to make communication as these query’s simple

1 answer

2


This site has everything you will 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();
  • vlw, only the first I clicked looks perfect, mto thanks..

  • Cool. Don’t forget to mark the answer as "correct".

  • @Nilsonuehara I recommend adding the piece of code described in your link here in the answer, because if for some reason the link is no longer available your answer will remain useful for everyone =)

  • @iTSangar well remembered. Code snippet added.

  • More like I create a Connection with my database?

  • @By the way you didn’t read the article from the beginning, because there it teaches step-by-step how to do this... anyway I changed my example... see there.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.