Need help with Image upload to database

Hii all,

Firstly, I'm rather new to Java technology and I'm currently working on a school project. I need some help with:

uploading of an image file to an online database server(MySQL) and,

retrieving the image from db(I'm using BLOB type) for display in Java.

I'm not familiar with the classes/methods to be used. Can someone help me here? Thanks!

[385 byte] By [marc79] at [2007-9-30 18:23:38]
# 1
Btw, I'm intending to use a simple UI with a button to click for user to choose image file to upload and another button to save the image to server. thanks!
marc79 at 2007-7-6 19:33:57 > top of Java-index,Administration Tools,Sun Connection...
# 2
Hope this can help: http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/JDBC20.html#JDBC2018_2
El_Duende at 2007-7-6 19:33:57 > top of Java-index,Administration Tools,Sun Connection...
# 3
Hi, thanks for the link.It has cleared some of my questions, but it does not show how I can do a File Select with Javax so that the user can choose an image instead of hardcoding it into the program. How can that be done in Java? Thanks!
marc79 at 2007-7-6 19:33:57 > top of Java-index,Administration Tools,Sun Connection...
# 4
Try JFileChooser http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.htmland the API documentation can be found here: http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFileChooser.html
lt.led at 2007-7-6 19:33:57 > top of Java-index,Administration Tools,Sun Connection...
# 5

Thanks for the link! I'm able to do a File Select via JFileChooser and display the image onto a JLabel using the ImageIcon method (many thanks for that!). Currently, this is what I have (ImageFilter() extends FileFilter):

ImageIcon photoIcon;

JLabel photoLabel = new JLabel();

JFileChooser fc = new JFileChooser();

<snip>

private JPanel DPCtr()

{

<snip>

photoIcon = new ImageIcon("default.jpg");

photoLabel.setIcon(photoIcon);

photoLabel.setPreferredSize(new Dimension(150, 150));

<snip>

return p;

}

<snip>

public void actionPerformed(ActionEvent a)

{

if (a.getSource() == browseBut) {

fc.setFileFilter(new ImageFilter());

int returnVal = fc.showOpenDialog(DiseasePane.this);

if (returnVal == JFileChooser.APPROVE_OPTION) {

File imgFile = fc.getSelectedFile();

try {

photoIcon = new ImageIcon(imgFile.toURL());

} catch (MalformedURLException e) {

System.err.println("Invalid URL");

}

photoLabel.setIcon(photoIcon);

}

}

}

marc79 at 2007-7-6 19:33:57 > top of Java-index,Administration Tools,Sun Connection...