Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet inserting multiple file formats into database
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


aswinks
inserting multiple file formats into database
1 Answer(s)      2 years and 8 months ago
Posted in : JSP-Servlet


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


Advertisement
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
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
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
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
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
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
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 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 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
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
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
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 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
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
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... into dlogin values(?,?,?)"); File file = new File(url); FileInputStream fs = new FileInputStream(file); ps.setString(1,usname); ps.setString(2,pass
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... into dlogin values(?,?,?)"); File file = new File(url); FileInputStream fs = new FileInputStream(file); ps.setString(1,usname); ps.setString(2,pass
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
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
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
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... file upload form to the user</TITLE></HEAD> <BODY> <FORM
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
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
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
Advertisements
 

 

 

DMCA.com