Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class ConeccionJBDC {
- public static void main(String[] args) throws SQLException{
- Connection con = obtConeccion();
- if(con != null){
- Statement sen = con.createStatement();
- ResultSet resultado = sen.executeQuery("Select* from socios");
- while(resultado.next()){
- System.out.println(resultado.getString("direccion" +
- ""));
- }
- }
- }
- public static Connection obtConeccion(){
- Connection R = null;
- boolean hayDriver = false;
- try {
- Class.forName("org.postgresql.Driver");
- hayDriver = true;
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if(hayDriver){
- try {
- R = DriverManager.getConnection("jdbc:postgresql://pg-devel.palermo.com.py:5432/pruebas","admin","adminadmin");
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return R;
- }
- }
Add Comment
Please, Sign In to add comment