inserting multiple file formats into database

Ads
 

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!");
%>

Ads









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
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
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
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 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
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
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
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
File insertion into oracle database
File insertion into oracle database  How to Read and Insert a file (any format) into a Oracle database
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?   Hi Friend, Please visit the following link: Upload Multiple Files Thanks
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
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
How to convert XML file to database ?
How to convert XML file to database ?  How to convert XML file to database
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
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
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;"> <
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
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

Ads