jueves, 19 de febrero de 2015

metodo para ajustar una fecha desde programacion a jdatechooser

Ojo debes tener en cuenta el formato de la fecha, pues puede lanzarte algun error 

private void ajustarFecha(String fecha) {
        SimpleDateFormat formatoDelTexto = new SimpleDateFormat("yyyy-MM-dd");    
        Date dato = null;
        try {
            dato = (Date) formatoDelTexto.parse(fecha);
        } catch (ParseException ex) { ex.printStackTrace(); }
        this.fecha.setDate(dato);
    }

jueves, 12 de febrero de 2015

CREATE TABLE IF NOT EXITS EN POSTGRES

El ejemplo que das y tu pregunta no coinciden.
Si quieres borrar una tabla solamente si existe puedes utilizar el comando:
DROP TABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
En tu caso, para borrar la tabla 'empdatos' solo si existe puedes ejecutar:
DROP TABLE IF EXISTS empdatos;
Pero para el comando CREATE TABLE no tenemos la opcion IF EXISTS. Asi que podriamos crear una función si no quieres que te de error al crearla (si existe). Aqui tienes un ejemplo:
CREATE OR REPLACE FUNCTION crear_tabla(TEXT) RETURNS VOID AS $$
DECLARE
 nombre_tabla ALIAS FOR $1;

BEGIN
    IF NOT EXISTS (SELECT * FROM information_schema.tables WHERE table_name = nombre_tabla) THEN

        execute 'CREATE TABLE ' || nombre_tabla || '(
            id int not null,
            name text,
            primary key (id)
        )';

    END IF;
END;
$$ LANGUAGE plpgsql;
Esta función la podrias usar asi:
test003=# \d
No relations found.

test003=# SELECT crear_tabla('test201');

test003=# \d
          List of relations
 Schema |  Name   | Type  |  Owner   
--------+---------+-------+----------
 public | test201 | table | postgres
(1 rows)