Package ejemplocdbpostgres

Source Code of ejemplocdbpostgres.EjemploCDBPostGres

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ejemplocdbpostgres;

import biblioteca.admin.utilidades.ConDb;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
*
* @author ernaes.trujillo
*/
public class EjemploCDBPostGres {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        ConDb con=new ConDb();
        Connection conn = null;
        try {
            conn = con.getSource().getConnection();
           
            /*String ins="insert into alumno values(?,?,?,?,?);";
            PreparedStatement pst=conn.prepareStatement(ins);
            pst.setInt(1, 6);
            pst.setString(2, "MARTHA ALICIA");
            pst.setString(3, "OCHOA");
            pst.setString(4, "CASTRO");
            pst.setInt(5,1);
            pst.executeUpdate();*/
           
            String ins="update alumno set nombre=? where id=3;";
            PreparedStatement pst=conn.prepareStatement(ins);
            pst.setString(1, "JUAN CARLOS");
            pst.executeUpdate();
           
            Statement sentencia = conn.createStatement();
           
            String query="select * from alumno;";
            ResultSet rs=sentencia.executeQuery(query);
            while(rs.next()){
                System.out.println("Nombre:"+rs.getString(2));
                System.out.println("Apellido Paterno:"+rs.getString(3));
                System.out.println("Apellido Materno:"+rs.getString(4));
            }
           
        } catch (SQLException e) {
            System.out.println("Error de coneccion;"+e.getMessage());
        } finally {
            if (conn != null) {
                try { conn.close(); } catch (SQLException e) {}
            }
        }
       
    }
   
}
TOP

Related Classes of ejemplocdbpostgres.EjemploCDBPostGres

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.