Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Conexion {
- public static void main(String args[]){
- try {
- Class.forName("com.mysql.jdbc.Driver");
- //Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/agenda", "root", " ");
- //Connection conexion = DriverManager.getConnection("jdbc:mysql://127.0.0.1/agenda?user=root;password=");
- java.sql.Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/agenda", "root", "");
- Statement instruccion = (Statement) conexion.createStatement();
- ResultSet tabla=((java.sql.Statement) instruccion).executeQuery("SELECT Idcontacto, Nombre, Apellido FROM contacto");
- System.out.println("Codigo\tnombre");
- while(tabla.next())
- System.out.println(tabla.getInt(1)+"\t"+tabla.getString(2)+"\t"+tabla.getString(3));
- }
- catch(ClassNotFoundException e){ System.out.println(e); }
- catch(SQLException e){ System.out.println(e); }
- catch(Exception e){ System.out.println(e); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement