Administra tu Blog

¡Crea tu Blog Ya! Fácil y Gratis

Java ORACLE
Welcome!. Gracias por ingresar, espero guste.

28/09/2008 GMT 1

Carga Masiva de Datos con Java

paulonline @ 20:01

Este programa crea un archivo llamado script.sql con 1 000 000 de sentencias INSERT, la cantidad de INSERT es configurable.

 

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.util.Hashtable;

class CargaMasiva{

public static void main(String[] args){

try{

File f=new File("/u01/app.oracle/product/10.2.0/db_1/script.sql");

FileOutputSteam fos=new FileOutputStream(f);

f.createNewFile();

if(f.canWrite()){

Hashtable ht=new Hashtable();

//Aquí se configura la cantidad de registros INSERT

String[] foo=new String[1000000];

//Este es el objeto que representa la tabla

Customer c=new Customer();

for(int i=0;i

      /*Guarda en el array los inserts. Aquí se puede añadir los registros de   una tabla mediante POO*/

foo[i]=

"INSERT INTO CUSTOMER(CUSTOMER_ID) VALUES('"+i+"');\n";

ht.put(i,foo[i]);

}

c.setX(foo);

//Lee el array y los escribe en el archivo script.sql

for(int i=0;i

byte[] b=foo[i].getBytes();

fos.write(b);

}

}

}

catch(IOException ioe){ ioe.getMessage(); }

}

//Este es el bean que representa la tabla

class Customer(){

private String[] x;

public String[] getX(){

return x;

}

public void setX(String[] _x){

this.x=_x;

return;

}

}

}

/*

Se puede añadir más métodos y variables al Bean, por ejemplo :

public String nombre="";

public int edad=0;

private Date fecha;

Para hacerlo con PL /SQL se debe revisar la librería UTL_FILE, que lee y escribe archivos de PL/SQL y de sistema operativo.

También se puede revisar el método INSERT SELECT de ORACLE. Por ejemplo:

insert into depto80 (select * from employees where department_id=80);

ó

insert into just_names(first,last) (select first_name, last_name from employees)

*/

Comentarios

No hay Comentarios »

Dejar un Comentario


<a href> <em> <blockquote> <strong> <cite> <code> <ul> <li> <dl> <dt> <dd>

Contactar con la autora o autor | Archivo | ¡Crea tu Blog Ya! Fácil y Gratis