Consigo conectar no banco de dados mais não consigo fazer aparecer os dados que estão armazenados no banco.
Como que eu faço?
package teste1conexao;
import java.sql.*;
/**
*
*
*/
class conexao {
private Connection con;
private Statement stmt = null;
private ResultSet rs = null;
public void conecta()
{
try {
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://localhost/teste?" +
"user=root"; // String de conexão
con = DriverManager.getConnection(connectionUrl);
System.out.println("Conectado");
} catch (SQLException e) {
System.out.println("SQL Exception: "+ e.toString());
} catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: "+ cE.toString());
}
}
public void MostraDados() throws SQLException
{
//SQL query command
String SQL = "SELECT * FROM teste where nome like \"Car%\" ";
//String SQL = "SELECT * FROM teste";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
while (rs.next()) {
System.out.println(rs.getString("codigo")
+ " : " + rs.getString("nome") + " : "
+ rs.getString("idade"));
}
}