Share on Google+Share on Google+

1 Answer(s)      6 years and 7 months ago
Posted in : SQL

is it possible to upload the video on mysql database

View Answers

April 13, 2011 at 5:16 PM


<%@ page language="java" %>
<HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>
<BODY> <FORM ENCTYPE="multipart/form-data" ACTION="upload.jsp" METHOD=POST>
<table border="0" bgcolor=#ccFDDEE>
<td colspan="2" align="center"><B>UPLOAD THE FILE</B><center></td>
<td colspan="2" align="center">&nbsp;</td>
<td><b>Choose the file To Upload:</b></td>
<td><INPUT NAME="file" TYPE="file"></td>
<td colspan="2" align="center">&nbsp;</td>
<td colspan="2" align="center"><input type="submit" value="Send File"> </td>


<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="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(saveFile);
FileOutputStream fileOut = new FileOutputStream(ff);
fileOut.write(dataBytes, startPos, (endPos - startPos));
%><Br><table border="2"><tr><td><b>You have successfully upload the file:</b>
<% out.println(saveFile);%></td></tr></table>
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/test";
ResultSet rs = null;
PreparedStatement psmnt = null;
FileInputStream fis;
connection = DriverManager.getConnection(connectionURL, "root", "root");
File f = new File(saveFile);
psmnt = connection.prepareStatement("insert into file(file_data) values(?)");
fis = new FileInputStream(f);
psmnt.setBinaryStream(1, (InputStream)fis, (int)(f.length()));
int s = psmnt.executeUpdate();
System.out.println("Uploaded successfully !");
catch(Exception e){e.printStackTrace();}


Related Tutorials/Questions & Answers:
About MYSQL  is it possible to upload the video on mysql database   1)page.jsp: <%@ page language="java" %> <HTML> <... connectionURL = "jdbc:mysql://localhost:3306/test"; ResultSet rs = null
MySQL In this section we will read about what is MySQL, MySQL distribution, MySQL features, MySQL architecture etc. MySQL unofficially, pronounced as My... the database. The development, distribution, and support of MySQL is done
MySQL NOT IN In this section we will read about how to use the NOT IN function in MySQL with a simple example. MySQL NOT IN() function specifies... will demonstrate you about how to use MySQL not in() function. In this example we
MySQL Cast
MySQL Cast       Here, you will learn about the MySQL CAST() function.  CAST... table: (Using SELECT * FROM employee;) Here, you will learn about
MYSQL  How to create time and date based trigger in mysql   MySQL Time Trigger
MySQL Configuration
MySQL Configuration       In this lesson you will read about the configuration of MySQL . The MySQL server configuration normally started during  installation process
mysql  how to open\import table in .dbf format in mysql
MySQL Commands
MySQL Commands       In this section, we are going to read about the mysql commands. Each statement is sent to the server for the execution by MySQL. MySQL provides lots
MySql  what is default password of mySql, and how i configure mySql.   Hi, If you are installing MySQL on windows then you will have to provide the Password for the user root at the installation time. You may try
you need to download the mysql-connector jar file for connecting java program from mysql database.......   Hi friend, MySQL is open source database... is the link for the page from where you can understand how to Download and Install MySQL
Mysql Table
Mysql Table       MySQL Create Table Here, you will read the brief description about the MySQL create table.    Mysql Add
mysql  want the code for mysql nested select query with single where condition.want to select data from more than one table
MySQL By Date
MySQL By Date       In this section, you will learn about how to fetch the data in order by date in MySQL. We can arrange the data through the ORDER BY clause. In the following
About jsp
About jsp  Read Excel data using JSP and update MySQL databse
ABOUT Jtable
ABOUT Jtable  My Project is Exsice Management in java swing Desktop Application. I M Use Netbeans & Mysql . How can retrive Data in Jtable from Mysql Database in Net Beans
PDO MySQL: MySQL is one of the most popular open source database, in this current tutorial we will come to know how to connect MySQL with PHP using PDO. Most of the web developers use MySQL with PHP, and most of the examples in our
doubt about J2EE connetivity
doubt about J2EE connetivity  steps to connect J2EE components with MYSQL
MYSQL Database
MYSQL Database  Can any one brief me about how to use MYSQL Database... about creating table and using MYSQL, just follow the below link and it will provide you extensive knowledge about your query. http://www.roseindia.net/mysql
MySQL Training ? Online Free MySQL Training
want to know about MySQL, we are starting from installation to the development... Configuration In this lesson you will read about the configuration of MySQL... In this section you can learn about the uses of MySQL String functions
Check PHP MySQL Connectivity
Check PHP MySQL Connectivity: The first step of any kind of connectivity... can connect a PHP page with MySQL server. Following piece of code will help you to check whether your PHP web page has been connected with MySQL server
About Database
About Database  in my database i enter the date of birth as Birth_Date date but i dont know in which format we can mention the date of birth   In MySQL database, date should be entered in the following format: yyyy-mm
About Jsp
About Jsp  Hello sir, I am developing online Quiz project in jsp using MySql Database. I want to know that How I will show Questions from database One by One on Same page and also want to calculate Result for the User
MySQL Convert
MySQL Convert       This section describes about the MySQL convert. It provides a way for converting...: (Using SELECT * FROM employee;) In the following query we will use MySQL convert
Mysql Time Zone Conversion
Mysql Time Zone Conversion       The Tutorial illustrate you an example from 'Mysql Time Zone Conversion' that describes you about the time zone conversion. SYNTAX
MySQL Coalesce
MySQL Coalesce       In this section, you will learn about MySQL Coalesce. It selects the first non-null value of its arguments. Syntax: coalesce(value,..): It returns the first
MySQL Cursor
MySQL Cursor       Here we are going to describe about the MySQL cursor and how to declare, open...; There are following types of properties of MySQL cursor
MySQL By Week
MySQL By Week       In this section, you will learn about the MySQL By Week. If you want to get...(): MySQL has the function WEEK() which returns a week number.  For example
Welcome to the MySQL Tutorials
that you want to know about MySQL, we are starting from installation... In this lesson you will read about the configuration of MySQL... about describing the allowable syntax for identifiers in MySQL
MySQL Create Table
MySQL Create Table       Here, you will read the brief description about the MySQL create table...; There are following way to create MySQL table:            
About struts
About struts  How will we configure the struts
About java
About java   how we insert our database data into the jTable in java or how we show database content into the JTable...("jdbc:mysql://localhost:3306/test", "root", "root"); Statement st


Advertisement null