And, How can I insert a file into a blob field?
I have a form in a file:
<FORM METHOD="POST" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="fichero">
<INPUT TYPE=SUBMIT NAME="bSubmit">
</FORM>
and when it is submitted I call a jsp page who use a Bean to manipulate a table of
the data base (Informix)
I dont know how to insert this file in a field of this table, the code of the
function of my bean I call is below
**************************
public void insertIntoTable(String fich) {
Connection conn=null;
PreparedStatement pstmt=null;
try {
Class.forName(classname);
} catch (Exception e) {
System.out.println("ERROR: failed to load Informix JDBC driver.");
}
try {
conn = DriverManager.getConnection(urlbd);
} catch (SQLException e) {
System.out.println("ERROR: failed to connect!");
}
try {
pstmt = conn.prepareStatement("insert into mitabla(fichero) values (?)");
} catch (SQLException e) {
System.out.println("Failed to Insert into mitabla: " + e.toString());
}
File file = new File(fich);
int fileLength = (int) file.length();
InputStream value = null;
FileInputStream fileinp = null;
int row = 0;
String str = null;
int rc = 0;
ResultSet rs = null;
System.out.println("Inserting data ...\n");
try{
fileinp = new FileInputStream(file);
value = (InputStream)fileinp;
} catch (Exception e) {}
try {
pstmt.setBinaryStream(1,value,fileLength); //set 1st column
} catch (SQLException e) {
System.out.println("Unable to set parameter");
}
try {
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println("Failed to Insert into tab: " + e.toString());
e.printStackTrace();
}
}
****************************
.
Thanks
Alexander Bonilla escribi�:
> Prueba con esto:
>
> java.sql.Statement stmt = myconnection.createStatement();
> ResultSet myresultset =stmt.executeQuery("select data from table where id=1
> ");
>
> byte data[] = null;
> while (res.next()) {
> data = res.getBytes(1);
> }
>
> Saludos.
>
> Alex.
>
> From: Winnie Leung <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> Subject: Re: BLOBS
> Date: Mon, 2 Jul 2001 11:07:37 +0100
>
> I can get it from oracle, but not sure about the others.
>
> java.sql.Statement stmt = myconnection.createStatement();
> ResultSet myresultset =stmt.executeQuery("select data from table where id=1
> ");
>
> BFILE bfile = null;
> while (res.next()) {
> bfile = ((OracleResultSet)res).getBFILE (1);
> out.println("Just got the BFILE!");
> }
>
> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Gemma Montero
> Sent: 02 July 2001 07:58
> To: [EMAIL PROTECTED]
> Subject: BLOBS
>
> Hi,
>
> Can anybody send me some sample code to store and retreive blobs from a
> database ?
>
> Thank you.
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets