You are on page 1of 1

try{

Class.forName("con.mysql.jdbc.Driver");

con=DriverManager.getConnection("jdbc:mysql://localhost:3306/vigilancia","root","ca
mila27");
}catch (ClassNotFoundException | SQLException e){
System.err.print("Error "+e);
}

}
public static void main(String[] args) {
Conexion cn = new Conexion();
Statement st;
ResultSet rs;
try {
st = (Statement) cn.con.createStatement();
rs= st.executeQuery("SELEC * FROM empresa" );
while (rs.next()){
System.out.println(rs.getString("idempresa")+" -
"+rs.getString("nombre"));
}
cn.con.close();
}catch (SQLException e){
}

try{
Class.forName("con.mysql.jdbc.Driver");

con=DriverManager.getConnection("jdbc:mysql://localhost:3306/vigilancia","root","ca
mila27");
}catch (ClassNotFoundException | SQLException e){
System.err.print("Error "+e);
}

}
public static void main(String[] args) {
Conexion cn = new Conexion();
Statement st;
ResultSet rs;
try {
st = (Statement) cn.con.createStatement();
rs= st.executeQuery("SELEC * FROM empresa" );
while (rs.next()){
System.out.println(rs.getString("idempresa")+" -
"+rs.getString("nombre"));
}
cn.con.close();
}catch (SQLException e){
}

You might also like