how to retrieve a file.

Hi friends I have inserted a file. The following coding working well. Will you please tell me how to retrieve the file in mysql database and jsp.If anybody knows please tell me.

insert a file in mysql and jsp

PreparedStatement ps = conn.prepareStatement("insert into table_user_file1(USER_USERNAME,USER_FILENAME,USER_FILEBIN) values (?,?,?)");

ps.setString(1,uname);

ps.setString(2,filename);

File file = new File(filebin);

FileInputStream fis = new FileInputStream(file);

ps.setBinaryStream(3,fis,(int)file.length());

ps.executeUpdate();

Thanks in advance;

[618 byte] By [sherin_poojaa] at [2007-10-2 20:31:40]
# 1
Well, you inserted the file using an INSERT sql statement, so to retrieve it again you need to use a SELECT sql statement. This will require you to uniquely identify the record, such as the username you also store in the same record.
gimbal2a at 2007-7-13 23:14:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi friend i have used this coding. but error.will u please tell me what is the correct format to retrieve a file in database and jsp. if u know retrieve a file coding please tell me.

String uname = request.getParameter("userName");

PreparedStatement pstmt = conn.prepareStatement("SELECT user_filebin FROM table_user_file1 WHERE user_username = ?");

pstmt.setString(1, uname1);

RandomAccessFile raf = new RandomAccessFile(uname1,"rw");

rs = pstmt.executeQuery();

if(rs.next())

{

Blob blob = rs.getBlob(1);

int length = (int)blob.length();

byte [] _blob = blob.getBytes(1, length);

raf.write(_blob);

}

Thanks for Advance.

Regards

pooja.

sherin_poojaa at 2007-7-13 23:14:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hai friends the following code is, retrieve a file to store default path("F:/sherin.txt").

// download the file

PreparedStatement pstmt = conn.prepareStatement("SELECT user_filebin FROM table_user_file1 WHERE user_username = ?");

pstmt.setString(1, uname1);

RandomAccessFile raf = new RandomAccessFile("F:/ss.txt","rw");

rs = pstmt.executeQuery();

if(rs.next())

{

Blob blob = rs.getBlob(1);

int length = (int)blob.length();

byte [] _blob = blob.getBytes(1, length);

raf.write(_blob);

}

But i want one dialog box open. The dialog box contains (open, save,cancel like windows format. if anybody know this concept.

regards

sherin

sherin_poojaa at 2007-7-13 23:14:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...