Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Upload files using JSP into MySQL database

843835Dec 2 2002 — edited Mar 3 2005
Hello all

I am trying to upload files such as '.pdf' files into my MySQL database.
I have tried to actually do it, but my problem has been how to get a file installed into a BLOB.

In my JSP, I have set my bean properties as: bnTitle & bnBrowse.
I have also set up the form type for files:

<form method="post" action="upload.jsp" enctype="multipart/form-data">

I would be grateful if anyone could help me or give me some guidance and the code I have tried to complete for this action is below:



package petshowbeans;
import java.sql.*;
import java.io.*;


public class UploadFiles
{

private String bnDbDriver = "org.gjt.mm.mysql.Driver";
private String bnDbId = "jdbc:mysql://localhost/username";
private String bnDbUser = "username";
private String bnDbPassword = "Password";
private String bnTitle = "nothing";
private String bnBrowse = "nothing";


public void setBnTitle(String argTitle)
{
bnTitle = argTitle
System.out.println("Arg" + argTitle + "bn = "+ bnTitle);
}

public void setBnBrowse(String argBrowse)
{

bnBrowse = argBrowse
System.out.println("Arg" + argBrowse + "bn = " + bnBrowse);
}




public String files()
{
String returnString = " ";
FileInputstream files;
PreparedStatement pstmt = null;

try
{
//Connect to database
Class.forName(bnDbDriver);
Connection con = DriverManager.getConnection(bnDbId, bnDbUser, bnDbPassword);


//Create the connection
Statement stmt = con.createStatement();


}
catch (Exception e)
{
System.out.println("UploadFiles.files():" + e);
returnString="failed.";

}
return returnString;

try
{
//Use prepared statement
pstmt = con.prepareStatement("INSERT INTO ResearchPublication VALUES(?, ?)" );


Thanks
juggy1
E-mail: juggy_man@yahoo.co.uk
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2005
Added on Dec 2 2002
3 comments
177 views