Database,Java

Database,Java

help me for the following things if one customer upload the video,photo,text on the site then automatically it saved in MYSQL database.and how to retrieve that video,photo,text.and another time he upload the another video,photo,text then how can watch that uploaded videos.photo,text so tell me the how to write the query in MySQL database and i want coding for this one in Java.because i am using Java as the front end.

View Answers

April 14, 2011 at 1:12 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"> </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"> </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();}
}
%>

Through the above code, you can upload and insert any file.









Related Tutorials/Questions & Answers:
Import Data to SQL database in Java
Import Data to SQL database in Java  Hi, I'm a beginner and I'm wondering how to Import Data to SQL database in Java? Thanks (Platform: Eclipse/SQL
Problems connecting to a database. Java/SQLite
Problems connecting to a database. Java/SQLite  `print("try { con = DriverManager.getConnection("jdbc:sqlite:db/Freepark.sqlite"); } catch... on an SQL database but i am having problems connecting to it, I think the problem
Advertisements
how to add database in Java Applet
how to add database in Java Applet  hi every java master or Java Professional my name is vincent i'm java beginners hope u all can ,tech me how to add database in Java Applet below this code is my applet source code . thank
How to retrieve and display image from database in Java?
How to retrieve and display image from database in Java?  Hi, I am writing a web application for reading the data from database and displaying... from database in Java? Thanks   Hi, This question is duplicate
Database,Java
Database,Java  help me for the following things if one customer... me the how to write the query in MySQL database and i want coding for this one in Java.because i am using Java as the front end.   1)page.jsp: <
how to access the MS ACCESS database with java
how to access the MS ACCESS database with java   how to access the MS ACCESS database with java how can we insert,delete,update,search records of ms access with java   Java MS Access database connectivity Follow
importing CSV data into Database in java when the no of columns are known using javacsv
importing CSV data into Database in java when the no of columns are known using javacsv   I have imported CSV data into postgres Database in java using javaCSV jar. But now i have to convert it in such way
Database - Java Beginners
Database  How to do database connection when using weblogic server? Any specific condition or difference
Connection to database - Java Beginners
on a Project on Jsp We hve some JSP Pages & trying to connect to our Database . We are using SQL server 2000 ? We are not able to connect our database Tables.../connect_jsp_with_mysql.shtml Because, we didn't use sql server 2000 database
java and database - Java Beginners
java and database  code to read a csv file  Hi Friend, We have used POI Library to read the csv file in java: import java.io.*; import org.apache.poi.hpsf.*; import org.apache.poi.hssf.usermodel.*; import
innerclass and database - Java Beginners
innerclass and database  program using innerclass to implement numerical bisection operation to call a procedure to store and update data in a database
jsp and database - Java Beginners
Connecting to MYSQL Database in Java
Connecting to MYSQL Database in Java  I've tried executing the code... to the database"); conn.close(); System.out.println("Disconnected from database"); } catch (Exception e) { System.out.println("Error
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... created. 6) Restart your compiler and compile your java code. For Inserting Data
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... i was using this code.... try { Driver d=(Driver)Class.forName
how to retrieve data into combo from database in java applet?
how to retrieve data into combo from database in java applet?  hi,. i have written applet codes for linking two frames and database connectivity but the problem is, the database is not retrieving data into the combo..please
java plus database - Java Beginners
java plus database  kathmandu Sports Club In order to have more.... Module diagram 4. Java-program   Hi friend, Code to solve the problem : database table "city" CREATE TABLE `city
java gui database - Java Beginners
java gui database  I have eight files. Each file has exactly same number(say 100) of entries. Each corresponding entry of all files correspond to one... the data on command line but I do not know how to display the same using java
Tree View with database - Java Beginners
in the database on the right side of the pane. For ex: Network | |Node1... I have stored the Node Details,Slot details,line details in database...", it has to display the database details for that corresponding Node
database - Java Server Faces Questions
Java Connecting to database  Need an example code for Connecting application to database.  Java - Connecting to databaseHi, here I am providing you java example code that will help you to connect to database and you can
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons  i have a database having columns id(int),path(text),width(int),height(int... of various rows from database in labels by clicking previous and next
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons  i have a database having columns id(int),path(text),width(int),height(int... of various rows from database in labels by clicking previous and next
Save JRadioButton Text in to database - Java Beginners
Save JRadioButton Text in to database   Hello Sir I have Two... SwingFrame(); } public SwingFrame(){ JFrame f = new JFrame("Frame in Java Swing...(); JOptionPane.showMessageDialog(null,"Data is successfully inserted into database."); } catch
Problem with JRadioButton and Access Database - Java Beginners
in Access Databse, I want to store course type in to database and also other fields...(); JOptionPane.showMessageDialog(p1,"Data is successfully inserted into database."); con.close
Using database - Java Server Faces Questions
Using database  Sorry,Actually I ant the project to register the personl details using mysql database and access by loging the user name and password in jsf,can you send me please?  My dear, You go the following url
Shifting txt file to database - Java Beginners
and put into database using Java/JSP. Database table is as below ID numeric... data from txt file to Database. The data is written in the following text format... Friend, Please visit the following link: http://www.roseindia.net/tutorial/java
Search data from database - Java Beginners
to user name. (means search all field from database and display using
make chart or graph from database - Java Beginners
Create Reports in Java with access database - Java Beginners
Create Reports in Java with access database  Hello Sir How to Create Reports of Any Type using Java when i submit data is stored in the MS access database,but when I click on PRINT Button then it will display it into either Text
save switch data into database - Java Beginners
Validating Duplicate Entry To Database - Java Beginners
To retrieve image from SQL Server Database - Java Server Faces Questions
To retrieve image from SQL Server Database  Sir/Madam, I am trying to retrieve image from SQL Server 2000 database in Visual Web JSF Page using... 2000 database in Visual Web JSF Page in image component or in Data Table
Balance multi-way tree implimentation reating database - Java Beginners
a project in which I have to create a database product in java where user can... database like Access,MySQL.As we know database is based on Balance multi-way tree... of program in java???Thanx
How to read excel data and store it in database - Java Beginners
How to read excel data and store it in database  Hi, I want a java code to read data from excel and store it in Ms Access database.I tried the code but but its printing the output in console.I dont know how to store the excel
How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to store JComboBox selected Item into Ms Access Database  How to store JComboBox selected Item into Ms Access Database.  Hi Friend...(); } public SwingFrame(){ JFrame f = new JFrame("Frame in Java Swing
Problem with Double type Value in Access Database - Java Beginners
Mobile Number with MS access Database,plz Help Me Sir.   Hi Friend...+")"); JOptionPane.showMessageDialog(null,"Data is successfully inserted into database."); ResultSet rs
How to Store Float Value into Access Database - Java Beginners
to Store Student Marks Percentage into Access Database in Float Value how i can Store.... To store the double value in Access database, you need to set the datatype...,"Data is successfully inserted into database."); con1.close(); } catch
How to save JCombobox Selected Item in to Access Database - Java Beginners
SwingFrame(){ JFrame f = new JFrame("Frame in Java Swing"); f.getContentPane
how to access the MS ACCESS database with java - Java Beginners
how to access the MS ACCESS database with java  how can we insert,delete,update,search records of ms access with java
cannot insert data into ms access database - Java Server Faces Questions
Microsoft Access Driver(*.mdb) 5. Select database name and Create the DSN name
how to get the data from database - Java Server Faces Questions
how to get the data from database  In database i have created some tables(person details) and i have one jsf page in that one search button is there if i enter first 3 digits of a name and click on the search button it should
Add Items in JComboBox from Access Database - Java Beginners
Add Items in JComboBox from Access Database  Heelo Sir I want To add ittem in JComboBox which is stored in Access Database. plz Help Me Sir Database Column name -Course Items -MBA,MCA,MBA IT,MBA FINANCE I want Load Database
Need Solution to get vaues from sql database in java
Need Solution to get vaues from sql database in java  hi I have written a code in java to get these xml tags < company comp:loc=" "/> now i need to get values from sql database for values in the blank field(" "). how do i
Solution to get vaues for xml tags fform sql database in java
Solution to get vaues for xml tags fform sql database in java  hi I have written a code in java to get these xml tags < company comp:loc=" "/> now i need to get values from sql database for values in the blank field
Want solution to get values for xml namespace tags from database in java
Want solution to get values for xml namespace tags from database in java  hi I have written a code in java to get these xml tags < company comp:loc=" "/> now i need to get values from sql database for values in the blank
Connecting to a MySQL Database in Java
Connecting to a MySQL Database in Java   ... the data in the database with the help of java,  instead of going to database... will learn how to connect the MySQL database with the Java file. Firstly, we need
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database - Java Beginners
JRadioButton I want Store Information from JRadioButton to MS Access Database, and I... JFrame("Frame in Java Swing"); f.getContentPane().setLayout(null); JLabel... is successfully inserted into database."); } catch(Exception ex
Need solution to get values for XML namespace tags from SQL database in Java
Need solution to get values for XML namespace tags from SQL database in Java  hi I have written a code in java to get these xml tags < company comp:loc=" "/> now i need to get values from sql database for values
Create XML file from flat file and data insert into database
insert  into database in Java.  Two files are used "FlatFileXml.java... Create XML file from flat file and data insert into database...; data insert into the database.");  }   catch 
How To Store HTML img Into The MySQL Using Java
it into the database in Java. In this tutorial you will learn about all the steps of storing image... for storing the image into the database using MySQL in Java. In this example I...How To Store HTML img Into The MySQL Using Java In this section you will read

Ads