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



Home Answers Viewqa Java-Beginners uploading a text file into a database
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


faith kay
uploading a text file into a database
1 Answer(s)      2 years and 7 months ago
Posted in : Java Beginners


how to upload a text file into a database using jchooser


Advertisement
View Answers

April 24, 2012 at 4:28 PM


import java.io.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;

public class UploadTextFile {
     static File file;
        public static void main(String[] args) throws Exception {

               JLabel label=new JLabel("Choose File: ");
               final JTextField text=new JTextField(20);
               JButton b1=new JButton("Browse");
               JButton b2=new JButton("Upload");
               b1.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                   JFileChooser chooser=new  JFileChooser();
               int returnVal = chooser.showOpenDialog(null);
               if(returnVal == JFileChooser.APPROVE_OPTION) {
                file = chooser.getSelectedFile();
                text.setText(file.getPath());
                   }
                   }
               });

               b2.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                       try{
                FileInputStream fis = new FileInputStream(file);
                Class.forName("com.mysql.jdbc.Driver");
                Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
                PreparedStatement pstmt = conn.prepareStatement("insert into myfile( file_name, file_data) values ( ?, ?)");
                pstmt.setString(1, file.getName());
                pstmt.setBinaryStream(2, fis, (int) file.length());
                pstmt.executeUpdate();
                JOptionPane.showMessageDialog(null,"Uploaded successfully to database");
                pstmt.close();
                conn.close();
                       }
                       catch(Exception ex){
                       System.out.println(ex);
                       }
                   }
               });
               JFrame f=new JFrame();
               f.setLayout(null);
               label.setBounds(10,10,100,20);
               text.setBounds(110,10,100,20);
               b1.setBounds(220,10,80,20);
               b2.setBounds(310,10,80,20);
               f.add(label);
               f.add(text);
               f.add(b1);
               f.add(b2);
               f.setVisible(true);
               f.setSize(450,200);               
        }
}


Related Tutorials/Questions & Answers:
uploading a text file into a database
uploading a text file into a database  how to upload a text file into a database using jchooser   import java.io.*; import java.sql.... { static File file; public static void main(String[] args) throws Exception
Uploading a Profile with image[file] into a sql database
Uploading a Profile with image[file] into a sql database  I need to upload a file along with the some text into a database ......[ Similar to http... , but upload file to database ] ... Pls help
Advertisements
uploading a file
uploading a file  When I am trying to upload a file to another system in lan at a location "http://192.168.12.5:8080/tomcat-docs/myapps",then it is giving the following error message "http://192.168.12.5:8080/tomcat-docs/myapps
file uploading
file uploading  How to upload music files onto the server and save the file information to the mysql database fetch and play the music files on a display page without download thus streaming the files
uploading audio file iphone
uploading audio file iphone  uploading audio file iphone
Question about "Insert text file data into Database"
Question about "Insert text file data into Database"  Hey I was reading the tutorial "Insert text file data into Database", (awesome btw), and noticed that both a FileInputStream, a DataInputStream and a BufferedReader
Uploading a Software and storing in the database
Uploading a Software and storing in the database  I want to upload a software(may be of maximum 20mb) through JSP, and store it in the database. The coding present in the site for uploading and storing in the database
query related to uploading file
to save the uploading time and date in database. please help me it is urgent...query related to uploading file  hello friends i am doing my project in servlet and i want to upload a file and store file in local hard drive
Uploading File on Server
Uploading File on Server  Hello, Can someone explain or suggest example. How do i uploading files on the FTP Server. Thanks
Struts file uploading - Struts
Struts file uploading   Hi all, My application I am uploading... and append it in the database. Ultimately all the file content should be stored in the database without breaking and user should be able to download the file
uploading file to tomcat server
uploading file to tomcat server  please tell me how to upload a file to the URL "http://192.168.12.7:8000/tomcat-docs/" ? thanks
File uploading - Ajax
File uploading  hi friends, how to uploading the file by using "AJAX".Please send the complete source code for this application   where u want to store the file Can u specify
Uploading a file using UploadBean
Uploading a file using UploadBean  Dear sir, In my project i have to upload the file and use the same file for getting a values from that uploaded .xls file.I used UploadBean for uploading .For the first time when i
Uploading and download pdf or .txt file.
Uploading and download pdf or .txt file.  I want admin user to upload pdf file into database and the users can download those pdf format from database
File uploading - JSP-Servlet
File uploading  i am using file uploading code for multiple file and aslo for single file but i am getting problem that No such file found.... http://www.roseindia.net/jsp/file_upload/Sinle_upload.xhtml.shtml
Drag and drop file uploading - Ajax
Drag and drop file uploading  Hi all, This is NageswaraRao i want file uploading feature on my web development..using drag and drop mouse functionality. Problem:I have Created one Text area when i drop the file on text area
Insert text file data into Database
Insert text file data into Database In this section, you will learn how to insert the text file data into the database. For this purpose, we have created a 'student.txt' file consisting of students information i.e, id, name, course
Uploading a .3gp file. - MobileApplications
Uploading a .3gp file.  sir, i m sending it again .i want code for java based mobile application, that can take .3GP video file and upload it to youtube using youtube's APIs. The video file would be located on a weblink
Uploading tha file - JSP-Servlet
Uploading tha file  hi,Sir. this is siddaiah. please give me response for the follwing questions. 1.how to upload file into oracle database using JSP? 2.How to upload photo into oracle database using JSP? Regards
File Uploading Problem
File Uploading Problem  I have a file uploading code but it create... = FileUpload.isMultipartContent(request); // Create a new file upload handler... { System.out.println("its a file"); System.out.println
File Uploading Problem
File Uploading Problem  I have a file uploading code but it create... = FileUpload.isMultipartContent(request); // Create a new file upload handler... { System.out.println("its a file"); System.out.println
file Uploading - Development process
file Uploading  Hi all, This is the problem i am facing please help me and solve the problem.i want upload file from my localpc(computer)to any textarea in webapplication.when i drop the mouse on text area the file content
file uploading using jsp
file uploading using jsp  below file uploading code has one error... = " + formDataLength); //String file = new String(dataBytes); //out.println("FileContents:" + file +""); byte[] line = new byte[128]; if (totalBytesRead
PHP error uploading file - PHP
PHP error uploading file  I am getting error while uploading a file in a folder in PHP ... Warning: Cannot modify header information - headers already send any idea
Write records into text file from database
Write records into text file from database You have already learnt how to insert records from text file to database. But here we are going to retrieve records from database and store the data into the text file. For this purpose, we have
file uploading - Java Beginners
file uploading   hi, i am developing one stand alone j2se programming in that i have to upload a file to another system in the LAN and have... is it should dispaly files from current system and asks whether this file is already
file uploading - JSP-Servlet
file uploading  Hi, thanks a lot for your kind answer. Now my program... problem. Im not geeting the full output for the program. Even, the file... to solve the problem as well. Thanks in advance. Input File
FILE UPLOADING - JSP-Servlet
FILE UPLOADING  Hi , I want Simple program for file upload using html and servlet plese help me  hi friend pls try this code ********** try{ String type=""; String boundary=""; String sz
file uploading - JavaMail
file uploading  Hi thi is swathi.Thank s for giving the answers to previous questions.I am getting the problem with below code FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new
Problem in uploading image to to mysql database
="text"></td> </tr> <tr> <td><b>Choose the file...Problem in uploading image to to mysql database  Hi, need some help... be save in the database. and the image will also save in the desired folder. i
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help... be save in the database. and the image will also save in the desired folder. i... the record to mysql database. heres my code... index.jsp <%@ page
Advertisements
 

 

 

DMCA.com