About MYSQL

About MYSQL

is it possible to upload the video on mysql database

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();}
}
%>

Ads









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 Cast
MySQL Cast       Here, you will learn about the MySQL CAST() function.  CAST... table: (Using SELECT * FROM employee;) Here, you will learn about
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
MYSQL  How to create time and date based trigger in mysql   MySQL Time Trigger
About jsp
About jsp  Read Excel data using JSP and update MySQL databse
mysql
mysql  how to open\import table in .dbf format in mysql
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
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 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
mysql
mysql  want the code for mysql nested select query with single where condition.want to select data from more than one table
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
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 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 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
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
About struts
About struts  How will we configure the struts
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 Java
About Java  Hi, Can anyone tell me the About Java programming language? How a c programmer can learn Java development techniques? Thanks   Hi, Read about java at http://www.roseindia.net/java. Thanks
about java
about java  how to get the value from the user like c, c++ program pls explain with example for me
How To Store Image Into MySQL Using Java
How To Store Image Into MySQL Using Java In this section we will discuss about how to store an image into the database using Java and MySQL. This example explains you about all the steps that how to store image into MySQL database
about jquery
about jquery  i want to put already made dropdown menu code which is in internet into my website.but how to put
About Main
About Main  can u create the object of one interface ? But i can able to create the abstract class through anonimous inner class.similarly can i
About Main
About Main  can u create the object of one interface ? But i can able to create the abstract class through anonimous inner class.similarly can i
about connectivity
about connectivity  hello i am basavaraj,will any one tell me how to use hibernate in struts.   Please visit the following link: Struts Hibernate Integration

Ads