Meu main
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package teste1conexao;
import java.sql.SQLException;
/**
*
-
@author Marcio
*/
public class Main {/**
-
@param args the command line arguments
*/
public static void main(String[] args) throws SQLException {
// TODO code application logic here
conexao obj1 = new conexao();
obj1.conecta();
obj1.MostraDados();
}
-
@param args the command line arguments
}
minha classe conexão
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package teste1conexao;
import java.sql.*;
/**
*
-
@author Marcio */ 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”)); }
}
}
não consigo visualizar as irnformações que estão dentro do banco de dados, pois ele só conecta.