inserting multiple file formats into database

inserting multiple file formats into database

hi i want to insert multiple file format like .pdf.doc.zip into mysql database using jsp.

View Answers

April 19, 2012 at 1:05 PM

Firstly, create a table 'myfile'in mysql database

CREATE TABLE `myfile` (                      
          `id` bigint(255) NOT NULL auto_increment,  
          `name` varchar(255) default NULL,          
          `file` longblob,                           
          PRIMARY KEY  (`id`)                        
        ) 

<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>

<%
String fileName = "c:/data.csv";

FileInputStream fis = null;
PreparedStatement pstmt = null;
try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
File file = new File(fileName);
fis = new FileInputStream(file);
pstmt = conn.prepareStatement("insert into myfile( name, file) values ( ?, ?)");
pstmt.setString(1, file.getName());
pstmt.setAsciiStream(2, fis, (int) file.length());
pstmt.executeUpdate();
pstmt.close();
fis.close();
conn.close();
} 
catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
} 
out.println("Inserted successfully!");
%>









Related Tutorials/Questions & Answers:
inserting multiple file formats into database
inserting multiple file formats into database  hi i want to insert multiple file format like .pdf.doc.zip into mysql database using jsp
inserting multiple file formats into database using html
inserting multiple file formats into database using html   hi the code was working fine,i want to choose the file and then upload to database,by using html.whether it is possible to upload larger file size,please explain
Advertisements
upload a file into database and progrm should support excel and text and csv file formats
upload a file into database and progrm should support excel and text and csv file formats  Hai all, I need a program to upload a file into database table... and the program should support .excel ,.txt ,.csv file formats. can
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
display multiple image file or pdf file in multiple column of a row from server or database
display multiple image file or pdf file in multiple column of a row from server or database  hello sir I have uploaded the file to the server and I want to display that file to the user page but I want to display that file
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
Inserting id in place of name to database
Inserting id in place of name to database  Hello, I have a database department where I have "id" and "name". I am fetching this data to a jsp form in dropdown list displaying "name" there and Now I wanted to insert data from
TO connect multiple database
TO connect multiple database  How to connect several database from a single application in java depending upon the user input it will connect to that database
inserting an path of an image in database - JDBC
inserting an path of an image in database  hello kindly help related... time its full path should be inserted in the database(MS Sql 2000).. I m able... be saved in the database...I have tried it but getting an error.. plz have a look
Data is not inserting correctly in mysql database.
Data is not inserting correctly in mysql database.  Hello Sir, below is my code to insert data into database by list iteration through for loop but it is not getting inserted ..it is taking only one value
urgent help for inserting database in a project
urgent help for inserting database in a project   I need some urgent... and then the result at the end.I need to add simple database connectivity... help me out quickly i am searching a lot..creating teh database si ok
urgent help for inserting database in a project
urgent help for inserting database in a project   I need some urgent... and then the result at the end.I need to add simple database connectivity... help me out quickly i am searching a lot..creating teh database si ok
Multiple File Upload in PHP
Multiple File Upload in PHP  Hi, I am beginner in PHP scripting language. I am very interested to learn PHP application. So, can anyone explain or provide related reference about how to Multiple file upload in PHP. Thanks
Inserting data on a database in servlet - JSP-Servlet
Inserting data on a database in servlet  Hi I am following... to a databse by a servlet.I used the example in "Inserting Data In Database table...:8080/DataInsertion/DataInsertion) in the browser, I just saw my designed database in the form
inserting text into text file using java application
inserting text into text file using java application  Hi, I want to insert a text or string into a text file using java application
Inserting data in Excel File - Java Beginners
Inserting data in Excel File  Dear Sir, How can we fill the excel with fetched data from the database like Oracle, DB2? Is it possible to create an excel with filled data? Kindly give me the solutions to questions
Inserting values into a database table of selected DropDown in jsp.
Inserting values into a database table of selected DropDown in jsp.  http://www.roseindia.net/answers/viewqa/Ajax/15250-DropDown-in-ajax+jsp.html Thank you for this program, it helped me alot to learn. I have done it. now i want
Multiple file upload - Struts
Multiple file upload  HI all, I m trying to upload multiple files... Multipale file Uploade Specify file: Specify file: Specify file
Lock while inserting/updating database in multithreaded.
Lock while inserting/updating database in multithreaded.  Hi, I am... inserting/updating to database. I dont know what is the issue but it was never... site but its coming at deployment site only. I verified all database indexes. I
inserting into mysql database with uid to be primary key and autoincrement
inserting into mysql database with uid to be primary key and autoincrement  hello, i am new to jsp and facing problem in creating a database entry...; Here is the code of inserting values from jsp form to database
getting error while inserting values in database
getting error while inserting values in database  AddUser.java import java.io.*; import java.sql.*; import javax.servlet.*; import...) { out.println("An Error Had occurred while accessing the database
display multiple images from postgres database in jframe
display multiple images from postgres database in jframe  i just want to display multiple images on jframe by firing a query on postgres database
in Spring MVC, i would like to download my Mysql database table in pdf,msword,excel formats.
in Spring MVC, i would like to download my Mysql database table in pdf,msword,excel formats.  in Spring MVC, i would like to download my Mysql database table in pdf,msword,excel formats: in View: radio buttons: pdf 2. mswod
J2ME Read Multiple File - MobileApplications
J2ME Read Multiple File  Hello I have read a topic "J2ME Read File", but that example is specify for a single file, but what if i want read more file one after the other just like Books. And an example will i appreciate thanks
multiple configurstion file in struts - Struts
multiple configurstion file in struts  Hi, Please tell me the solution. I have three configuration file as 'struts-config.xml','struts... in these three config file one by one respectively.So how I can place the code
Multiple file Uploading - JSP-Servlet
Multiple file Uploading   Hello everyone I am using jsp and my IDE is eclipse and back end is ms sql server i am trying to upload multiple... class for JSP: An error occurred at line: 9 in the generated java file
i am inserting an image into database but it is showing relative path not absolute path
i am inserting an image into database but it is showing relative path... = con.prepareStatement("insert into dlogin values(?,?,?)"); File file = new File(url); FileInputStream fs = new FileInputStream(file); ps.setString(1,usname
i am inserting an image into database but it is showing relative path not absolute path
i am inserting an image into database but it is showing relative path... = con.prepareStatement("insert into dlogin values(?,?,?)"); File file = new File(url); FileInputStream fs = new FileInputStream(file); ps.setString(1,usname
inserting data from radio buttons to database-ERROR - JSP-Servlet
inserting data from radio buttons to database-ERROR  hi, i have already changed the option field of table question. the code which you give me has the option field as options. but it is option in the table,so i changed
Retrieve multiple data from database into Table.....
Retrieve multiple data from database into Table.....   hi........... I want to Retrieve multiple data from database into Table but i am not able... database i have attributes pH, phosphate, ....... month, year......... so its
Facing Problem to insert Multiple Array values in database - JSP-Servlet
facing the problem while inserting the data in database. iam using the MsAccess... database but while inserting the data in orderdetails after insert the frist value its...Facing Problem to insert Multiple Array values in database  Hai
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, my problem is as follows: i am creating a feedback form of a college. this feedback form... button) now i have a database as professor and a table in this database
i am inserting an image into database but it is showing relative path not absolute path
i am inserting an image into database but it is showing relative path...="text" name="sname"><br><br> Upload photo:<input type="file...(); PreparedStatement ps = con.prepareStatement("insert into dlogin values(?,?,?)"); File file
multiple file upload at a time like gmail
multiple file upload at a time like gmail  I want to upload multiple files at a time like gmail. is there any possiblity/solution to do that?  ... Multiple Files Thanks
pint multiple images from blob database
pint multiple images from blob database  How to display multiple images using blob from mysql database. The program code is as below: <TABLE cellpadding="15" border="1" style="background-color: #ffffcc;"> <
Inserting Image in Database Table
Inserting Image in Database Table   ... an image is inserted into the database, it displays ?Inserting Successfully... to the MySQL database table.  Flow of the process : ADS_TO_REPLACE_1
inserting image in mysql database using browse button in servlets
inserting image in mysql database using browse button in servlets  Hi,I want to insert a image in mysql database using browse button. and, i want...;TITLE>Display file upload form to the user</TITLE></HEAD> <
File insertion into oracle database
File insertion into oracle database  How to Read and Insert a file (any format) into a Oracle database
Source file upload by attaching multiple files
Source file upload by attaching multiple files  Hi, I am trying to develop a file upload with multiple files attached functionality in java(like in gmail or in picasa). The source I found so far will select a single file. When I
create csv file in php in multiple columns
create csv file in php in multiple columns  i need create csv file in multiple columns like this: id name age date_added 1 john 23 2012-2-12 2 jane 25 2012-3-14 i can build csv file like this: id,name,age,date
create csv file in php in multiple columns
create csv file in php in multiple columns  i need create csv file in multiple columns like this: id name age date_added 1 john 23 2012-2-12 2 jane 25 2012-3-14 i can build csv file like this: id,name,age,date
inserting data from radio buttons to database - JSP-Servlet
inserting data from radio buttons to database  hi, i am getting error in my code of feedback form. once i finished selecting all the radio buttons and when i click on delete button. it points to the answer.jsp. answer.jsp
Source file upload by attaching multiple files
Source file upload by attaching multiple files  Thanks for the answer. The answer posted in this link I want to have a single text box and when i... a provision to attach multiple images/files like in gmail. Is there any solution
Retrieving value from multiple table in database
Retrieving value from multiple table in database  Hi fnds, I want to maintain the financial database of 20 users for 1 year and update the details in jsp page.. so i have decided to maintain the details based on month (because
uploading a text file into a database
uploading a text file into a database  how to upload a text file into a database using jchooser   import java.io.*; import java.sql.... { static File file; public static void main(String[] args) throws Exception
Time schedular for multiple batch file execution in java
Time schedular for multiple batch file execution in java  Hello All, i have a task in which i have to design a time schedular in java in which i can automate the batch file execution for the wholw day. For example i should have
Displaying file from database
Displaying file from database  I have list of files in my database. I... that corresponding file from database. I have list of file id related to search. I want to retrieve and display all the file using list of file ID. Is there is any other way
Show multiple identical rows into JTable from database
Show multiple identical rows into JTable from database In this tutorial, you will learn how to display the multiple rows from database to JTable. Here is an example that search the data from the database and show multiple identical
Add a file into database
Add a file into database  Provide the code to upload a file into oracle database?   1)page.jsp <%@ page language="java" %> <Html> <HEAD><TITLE>Display file upload form to the user</TITLE>

Ads