continue..
class UploadAction extends AbstractAction {
public UploadAction(String text) { super(text); }
public void actionPerformed(ActionEvent evt) {
int selected = list.getSelectedIndex();
Object ob=null;
ob=model.getElementAt(selected);
String fileName=ob.toString();
File file=new File(fileName);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:
mysql://localhost:3306/test";, "root", "root");
PreparedStatement st = con.prepareStatement("insert into file(file,file_data) values(?,?)");
FileInputStream fis = new FileInputStream(file);
st.setString(1,fileName);
st.setBinaryStream(2, (InputStream)fis, (int)(file.length()));
int s = st.executeUpdate();
JOptionPane.showMessageDialog(null,"image is successfully uploaded and inserted.");
}
catch(Exception ex){}
}
}
class ImageCellRenderer extends JLabel implements ListCellRenderer {
public ImageCellRenderer() {
setOpaque(true);
setIconTextGap(12);
}
public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus){
File f = new File(value.toString());
Border empty = BorderFactory.createEmptyBorder(3,3,3,3);
Border matte = BorderFactory.createMatteBorder(0,0,1,0,Color.white);
setBorder(BorderFactory.createCompoundBorder(matte,empty));
setText(f.getName());
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image icon = toolkit.getImage(f.getPath());
Image scaledIcon = icon.getScaledInstance(40,40,Image.SCALE_FAST);
setIcon(new ImageIcon(scaledIcon));
if (isSelected) {
setBackground(new Color(61,128,223));
setForeground(Color.white);
} else if (index % 2 == 0) {
setBackground(new Color(237,243,254));
setForeground(Color.darkGray);
} else {
setBackground(Color.white);
setForeground(Color.darkGray);
}
return this;
}
}
class FileDropTargetListener extends DropTargetAdapter {
public void dragEnter(DropTargetDragEvent evt) {
frame.requestFocusInWindow();
}
public void drop(DropTargetDropEvent evt) {
try {
Transferable tr = evt.getTransferable();
DataFlavor [] flavors = tr.getTransferDataFlavors();
for ( int i = 0; i < flavors.length; i++ ) {
if ( flavors[i].isFlavorJavaFileListType() ) {
evt.acceptDrop(DnDConstants.ACTION_COPY);
java.util.List list2 = (java.util.List)tr.getTransferData(flavors[i]);
ArrayList filenames = new ArrayList();
for ( int j = 0; j < list2.size(); j++ ) {
String path = list2.get(j).toString();
if ( ((new ImageFileFilter()).accept(new File(path))) ) {
filenames.add(path);
}
}
if (filenames.size() > 0 ) {
int numAdded = addToListModel(filenames);
evt.dropComplete(true);
return;
}
}
JOptionPane.showMessageDialog(frame,"Error","Invalid File Type",JOptionPane.WARNING_MESSAGE);
evt.rejectDrop();
}
} catch (Exception e) {
e.printStackTrace();
evt.rejectDrop();
}
}
}
}
Thanks