Administra tu Blog

¡Crea tu Blog Ya! Fácil y Gratis

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

Archivo: Noviembre 2008

29/11/2008 GMT 1

La clase java.sql.Date de SQL: Ejemplo en DB

paulonline @ 00:00

Dicen que Java es potente

Otros dicen que Java es dificil

bueno, la verdad es que es potente y con pocas líneas de código puedes acceder a propiedades complicadas.

Tenemos lo siguiente:

PROBLEMA:

Parsear el tipo DATE de la base de datos para

sql="INSERT INTO TABLA (FECHA)  VALUES (TO_DATE(?,'DD-MON-RR'))";

SOLUCION:

Calendar c=new Calendar();

long l=c.getTimeInMillis();

Date d=new Date(l);

Entidad o=new Entidad();

o.setFecha(d); // de tipo DATE

 

y lo recoges con

PreparedStatement pre=con.prepareStatement(sql) ;

pre.setDate(1,o.getFecha());

y cambia el SQL a:

sql="INSERT INTO TABLA (FECHA)  VALUES (?)";

 

13/11/2008 GMT 1

Conexión cliente remoto con OracleXE 10g en Windows

paulonline @ 19:04

Ir a

http://www.oracle.com/technology/software/products/database/xe/htdocs/102xewinsoft.html

y descargar Oracle Database 10g Express Client OracleXEClient.exe (30,943,220 bytes)

Username: paul_lizardo@hotmail.com

Password:esyD7sJ

Hacer doble click en el instalador (suena muy infantil no?)

next, next, next...bueno instalar, click en Finish

Destination Folder: C:\XEClient\
Port for 'Oracle Services for Microsoft Transaction Server': 2030

Ejecutar RUN SQL Command Line y

conectarse:

CONNECT REPIP/REPIP@OSC2003:1521/XE

Calidad y servicio.

12/11/2008 GMT 1

Upload con struts-upload.war de Struts1.1

paulonline @ 20:01

Para hacer un upload con struts simplemente el archivo Upload.java tendria que modificarse como lo siguiente:

//File directorio=new File("c:\\archivosPDFsubidos");
//directorio.mkdir();
//String path=directorio+fileName+theForm.getTheText();
String path="c:\\"+fileName+theForm.getTheText();
try {
//retrieve the file data
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream stream = file.getInputStream();
if (!writeFile) {
//only write files out that are less than 1MB
if (file.getFileSize() < (4*1024000)) {

byte[] buffer = new byte[8192];
int bytesRead = 0;
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
baos.write(buffer, 0, bytesRead);
}
data = new String(baos.toByteArray());
}
else {
data = new String("The file is greater than 4MB, " +
" and has not been written to stream." +
" File Size: " + file.getFileSize() + " bytes. This is a" +
" limitation of this particular web application, hard-coded" +
" in org.apache.struts.webapp.upload.UploadAction");
}
}
else {
// Aquí está mi aporte
File f = new File(path);
FileOutputStream out = new FileOutputStream(f);
out.write(file.getFileData());
out.flush();
out.close();

//write the file to the file specified
OutputStream bos = new FileOutputStream(theForm.getFilePath());
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
data = "The file has been written to \"" + theForm.getFilePath() + "\"";
}
//close the stream
stream.close();
}
catch (FileNotFoundException fnfe) {
return null;
}
catch (IOException ioe) {
return null;
}

...probad el código y vereis que hace una carga en la unidad C: (bueno, he sido educado en idioma español)

de nada, a mi tampoco me salía, simplemente dije: si me sale lo coloco en mi blog.

Puedes mejorar reeemplzando los tag html de struts con simple HTML

 

upload.jpg


<%@ page import="org.apache.struts.action.*,
java.util.Iterator,
org.apache.struts.webapp.upload.UploadForm"%>
<%@ page language="java" %>


 



 

Pronto estaré con mayores novedades y aportaciones, por ejemplo hacer todo esto con Struts2 y con ADFBC.

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