image is display from path of mysql database
<%@ page import="java.io.,java.sql.,java.util.zip.*" %>
<%
String saveFile="";
String contentType = request.getContentType();
if((contentType != null)&&(contentType.indexOf("multipart/form-data") >= 0)){
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while(totalBytesRead < formDataLength){
byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\") + 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
File ff = new File("C://UploadedFiles//"+saveFile);
FileOutputStream fileOut = new FileOutputStream(ff);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
%>
You have successfully upload the file:<%out.println(saveFile);%> |
<%
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/roseindia";
PreparedStatement psmnt = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
psmnt = connection.prepareStatement("insert into file1(file_path) values(?)");
psmnt.setString(1, ff.getPath());
int s = psmnt.executeUpdate();
if(s>0){
System.out.println("Uploaded successfully !");
}
else{
System.out.println("Error!");
}
}
catch(Exception e){
e.printStackTrace();
}
}
%>
View Answers
Ads
Related Tutorials/Questions & Answers:
image is display from path of mysql database
image is
display from path of
mysql database <%@ page import...;%
Connection connection = null;
String connectionURL = "jdbc:
mysql://localhost..._
path) values(?)");
psmnt.setString(1, ff.getPath());
int s = psmnt.executeUpdate
Advertisements
How to retrieve image from mysql database in JSP?
How to retrieve
image from mysql database in JSP? Hi,
I need JSP same codes for learning to get
image which is stored in
MySQL Database.
How to retrieve
image from mysql database in JSP?
Thanks
Hi,
You can write
Fetching image from database
Fetching
image from database I have uploaded
image path and
image name in
database so, now how can i
display that
image using JSP or HTML page(is it possible to
display using tag using concatination).
image path i have stored
Retrieve image from mysql database through jsp
Retrieve
image from mysql database through
jsp... to retrieve
image from
mysql database through jsp code. First create a
database...' of
database 'mahendra'.
Structure of table 'save_
image'
First create
database named
Display Data from Database in JSP
Display Data
from Database
in JSP
This is detailed java program to connect java
application with
mysql database and execute query to
display data
from the
specified table.
Before
Retrieve image from database using Servlet
that connects to the
MySQL database and retrieves the
image from the
table. After...Retrieve
image from database using Servlet
 ... applications that retrieves the
image from database. You can use
this type
how to store image upload path to mssql database
how to store
image upload
path to mssql database hi there!!,
i need help in storing the
image upload
path into the
database. basically i just use file select to upload the
image from jsp to
database. however when i click submit
how to store image upload path to mssql database
how to store
image upload
path to mssql database hi there!!,
i need help in storing the
image upload
path into the
database. basically i just use file select to upload the
image from jsp to
database. however when i click submit
how to store image upload path to mssql database
how to store
image upload
path to mssql database hi there!!,
i need help in storing the
image upload
path into the
database. basically i just use file select to upload the
image from jsp to
database. however when i click submit
how to store image upload path to mssql database
how to store
image upload
path to mssql database hi there!!,
i need help in storing the
image upload
path into the
database. basically i just use file select to upload the
image from jsp to
database. however when i click submit
how to display records from database
how to
display records
from database I want to
display records
from database in tables, the
database is having 2000 records and i want to
display 20 records at a time and to use next and previous link buttons to show
display date to jsp from database
display date to jsp
from database display date to jsp
from database to calender
if the start date and end date is available than calender date... not available in
database field than show in green color and clickable.
NOTE :- Date
How to store and retrieve image from database in JSP?
How to store and retrieve
image from database in JSP? Hi,
In one... and retrieve
image from database in JSP?
Thanks
HI,
You can use... the
image. Check this example:
Retrieve
image from database using Servlet.
Thanks