Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18

Deprecated: Function eregi_replace() is deprecated in /home/jcmouse/public_html/app/code/include/model/database/pregunta.php on line 161

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18
datos en mysql - Code Army!
Te encuentras en el foro de MySQL

datos en mysql


Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18
problem
31/01/2013 10:05
park
Rango: Soldado
31/01/2013 09:51
Peru
1
0
Fecha de ingreso
Ubicacion
Preguntas
Respuestas

package principal;
import java.awt.Image;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
/**
*
* @author arthur
*/
public class fotoclass {
conexion con;
private Image data;

public fotoclass (){
con = new conexion();
}
public void Cerrar (){
con = new conexion();
}
/*Guardar la imagen JPG*/
public boolean guardarfoto(String foto){
boolean ok=false;
FileInputStream fis = null;
try {
File file = new File(foto);
fis = new FileInputStream(file);

PreparedStatement pstm = con.getConnection().prepareStatement("insert intro " +
" tImagenes(foto) " + " values(?,?)");
pstm.setBinaryStream(1,fis,(int) file.length());
pstm.execute();
pstm.close();
ok=true;
} catch (FileNotFoundException ex) {
Logger.getLogger(fotoclass.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException e) {
System.out.println(e);
} finally {
try {
fis.close();
} catch (IOException ex) {
Logger.getLogger(fotoclass.class.getName()).log(Level.SEVERE, null, ex);
}
}
return ok;
}

//metodo que dado un parametro "id" realiza una consulta y devuelve como resultado
// una imagen
public Image getfoto(String id){
try{
PreparedStatement pstm = con.getConnection().prepareStatement("SELECT " +


" foto " +
" FROM fotos " +
" where id = 000? ");
pstm.setString(1, id);
ResultSet res = pstm.executeQuery();
int i = 0;
while(res.next()){
//se lee la cadena de bytes de la base de datos
byte[] b = res.getBytes("foto");
// esta cadena de bytes sera convertida en una imagen
data = ConvertirImagen(b);
i++;
}
res.close();
} catch (IOException ex) {
Logger.getLogger(fotoclass.class.getName()).log(Level.SEVERE, null, ex);
}catch(SQLException e){
System.out.println(e);
}
return data;
}


//metodo que dada una cadena de bytes la convierte en una imagen con extension jpeg
private Image ConvertirImagen(byte[] bytes) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
Iterator readers = ImageIO.getImageReadersByFormatName("jpeg");
ImageReader reader = (ImageReader) readers.next();
Object source = bis;
ImageInputStream iis = ImageIO.createImageInputStream(source);
reader.setInput(iis, true);
ImageReadParam param = reader.getDefaultReadParam();
return reader.read(0, param);
}
}

x fas me ayudan tengo error porfa embien a mi correo arth.salas@yahoo.es

problem
 
.
X

Se parte de Code Army!

Esta acción es solo para usuarios registrados