Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import javax.sql.*;
- public class main {
- public static void main(String[] args) {
- Connection conn = null;
- try
- {
- String url = "jdbc:mysql://52.178.136.243:3306/Prueba";
- Class.forName ("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection (url,"root","1234asd");
- System.out.println ("Database connection established");
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- if (conn != null)
- {
- try
- {
- Statement stmt = null;
- stmt = conn.createStatement();
- String sql;
- sql = "SELECT * FROM Prueba.Cliente;";
- ResultSet rs = stmt.executeQuery(sql);
- while(rs.next()){
- //Retrieve by column name
- int id = rs.getInt("idCliente");
- String name = rs.getString("name");
- //Display values
- System.out.printf("ID: %d" , id);
- System.out.printf(", name: %s \n" , name);
- }
- }
- catch (Exception e) { /* ignore close errors */ }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement