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



Home Answers Viewqa SQL About MYSQL
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Sireesha
About MYSQL
1 Answer(s)      3 years and 6 months ago
Posted in : SQL


is it possible to upload the video on mysql database


Advertisement
View Answers

April 13, 2011 at 5:16 PM


1)page.jsp:

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

2)upload.jsp:

<%@ 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));
fileOut.flush();
fileOut.close();
%><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;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
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();
if(s>0){
System.out.println("Uploaded successfully !");
}
else{
System.out.println("Error!");
}
}
catch(Exception e){e.printStackTrace();}
}
%>


Related Tutorials/Questions & Answers:
About MYSQL
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
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
Advertisements
MySQL NOT IN
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
MYSQL  How to create time and date based trigger in mysql   MySQL Time Trigger
mysql
mysql  how to open\import table in .dbf format in mysql
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
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
mysql
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
mysql  want the code for mysql nested select query with single where condition.want to select data from more than one table
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 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 Table
Mysql Table       MySQL Create Table Here, you will read the brief description about the MySQL create table.    Mysql Add
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
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
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
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
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
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
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
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 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 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 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
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
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... will learn 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:            
Advertisements
 

 

 

DMCA.com