How does JSP store images and media files in Oracle?

Source: Internet
Author: User

Step 1: Create a database
Create Table test_img (
ID number (4 ),
Name varchar (20 ),
IMG long raw );

Step 2:
<HTML> <Body>
Add image <br>
<Form method = "Post" Action = "insertnews. jsp">
Image ID: <input name = "ID" size = "10">
<Br>
Select image: <input type = "file" name = "image">
<Br>
<Input type = "Submit" value = "Upload" name = "Submit" size = "25">
<Input type = "reset" value = "clear" name = "clear" size = "25">
<Br>
</Form>
</Body>

Step 3: insert the database (insertimg. jsp)

<% @ Page Language = "Java" %>
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "Java. util. *" %>
<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "Java. Text. *" %>
<% @ Page import = "Java. Io. *" %>

<%
Class. forname ("oracle. JDBC. Driver. oracledriver ");
String url = "JDBC: oracle: thin: @ Lubin: 1521: b2bdb ";
Connection con = drivermanager. getconnection (URL, "Demo", "Demo ");

// Insert a database
String SQL = "insert into test_img values (?,?,?) ";
// Obtain the upload value ID
String id = request. getparameter ("ID ");
// Obtain the image path
String KK = request. getparameter ("image ");
// Convert to file format
File filename = new file (kk );

// Read the file length and convert it to the long type
Long L1 = filename. Length ();
Int L2 = (INT) L1;

// Value assignment in stream format
Fileinputstream FCM = new fileinputstream (filename );

Preparedstatement PS = con. preparestatement (SQL );
PS. setstring (1, ID );
PS. setstring (2, filename. getname ());
PS. setbinarystream (3, FS, L2 );
Ps.exe cuteupdate ();
PS. Close ();
FCM. Close ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.