Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement