SHARE
TWEET

Untitled

a guest Oct 4th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class Conexion {
  3.     public static void main(String args[]){
  4.         try {
  5.             Class.forName("com.mysql.jdbc.Driver");
  6.             //Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/agenda", "root", " ");
  7.             //Connection conexion = DriverManager.getConnection("jdbc:mysql://127.0.0.1/agenda?user=root;password=");
  8.             java.sql.Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/agenda", "root", "");
  9.            
  10.             Statement instruccion = (Statement) conexion.createStatement();
  11.             ResultSet tabla=((java.sql.Statement) instruccion).executeQuery("SELECT Idcontacto, Nombre, Apellido FROM contacto");
  12.             System.out.println("Codigo\tnombre");
  13.             while(tabla.next())
  14.                 System.out.println(tabla.getInt(1)+"\t"+tabla.getString(2)+"\t"+tabla.getString(3));
  15.                
  16.         }
  17.         catch(ClassNotFoundException e){ System.out.println(e); }
  18.         catch(SQLException e){ System.out.println(e); }
  19.         catch(Exception e){ System.out.println(e); }
  20.     }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top