Home Answers Viewqa JDBC read text file and store the data in mysql

 
 


kameshwar
read text file and store the data in mysql
1 Answer(s)      3 years and 4 months ago
Posted in : JDBC

when we store the data in mysql table from text file its store the data from new line to new column. how to store the data in different column from a single line of text file.
View Answers

January 27, 2010 at 10:13 AM


Hi Friend,

Try the following code:

import java.io.*;
import java.sql.*;
import java.util.*;

public class InsertFileData{
public static void main(String[]args){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root");
Statement st=con.createStatement();

FileInputStream fstream = new FileInputStream("C:\\student.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
ArrayList list=new ArrayList();
while ((strLine = br.readLine()) != null){
list.add(strLine);
}
Iterator itr;
for (itr=list.iterator(); itr.hasNext(); ){
String str=itr.next().toString();
String [] splitSt =str.split(" ");
String id="",name="",course="",deptt="";
for (int i = 0 ; i < splitSt.length ; i++) {
id=splitSt[0];
name=splitSt[1];
course=splitSt[2];
deptt=splitSt[3];
}

int k=st.executeUpdate("insert into student(id,name,course,department) values('"+id+"','"+name+"','"+course+"','"+deptt+"')");

}
}
catch(Exception e){}
}
}

Thanks









Related Pages:
read text file and store the data in mysql - JDBC
read text file and store the data in mysql  when we store the data in mysql table from text file its store the data from new line to new column. how to store the data in different column from a single line of text file
how to store data in a text file - Java Beginners
how to store data in a text file  Hi friends, I want to know, how we can save the data in a .txt file using swings....... for example, i want to store the arraylist data of swing program into a text file.......and also i want
read from file and store using hash map
read from file and store using hash map  I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like Adults: Name, xyz
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row
how to read the values for text and csv files and store those values... or .txt) file and get the values from that file and store them into database... the data as content of file ==> siva,divya,ravi now it should
Read specific column data from text file in java
Read specific column data from text file in java  My question is if my text file contain 15 columns and i want read specific column data from that text file then what code i should do
How to read the data in text file seperated by by ',' in java using IO Operations
How to read the data in text file seperated by by ',' in java using IO Operations  in Text file data like raju 45,56,67 ramu 46,65,78 raji 34,23,56 this is the student marks in text file.this data read and calculate
store and retrieve data
store and retrieve data  sir,i want to store the entering data... for this?   Please visit the following links: Java Read word file Java Write data into word file For this, poi-scratchpad-3.7-20101029.jar is needed
Read Text file from Javascript - JSP-Servlet
Read Text file from Javascript  plz send the code How to Retrieve the data from .txt file thru Javascript? And how to find the perticular words in that file
store
store  i want to store data in (.dat) file format using swing and perform operation on that insertion,deletion and update
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
Java file read write operation
Java file read write operation  how to read and write the data from text file.Suppose i have text file with 4 fields name ,roll no ,marks1,marks2 with more than 20 records......i need to store these value in object and pass
How to read file in java
How to read file in java Java provides IO package to perform reading and writing operations with a file. In this section you will learn how to read a text... the given file name. read()-The read() method of FileInputStream class reads
Read Write
Read Write  Hi; How can I read certain line of say 10 text files and write to one text file   Java Read Multiple Files and store the data... and stored the data into another text file. import java.io.*; import
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... and department. Now to read this file, we have used DataInputStream and transfer
store data from a variable in mysql?
store data from a variable in mysql?  sir last time asked you tell me how to retrieve data from a database mysql and store it in an int variable in order to apply some calculation on it, but now i want to store the result
Write Text File to Table
the records of a simple text file and write (insert) into a simple table in MySQL database. All records are written in the simple text file and again, if you need... Write Text File to Table     
How to read a large text file line by line in java?
How to read a large text file line by line in java?  I have been assigned a work to read big text file and extract the data and save into database... memory assigned is also a limit. So, we have decided to read the text file line
for store data in data base - JSP-Servlet
for store data in data base  i want to a job site, in this site user..... and on 3rd form i use submit button... data of form 1 and 2 can also be store... { text-decoration: none; font-family:arial; font-size:12px; color: #000000
How to read text file in Servlets
Create a Table in Mysql database through SQL Query in JSP...; This is detailed java code to connect a jsp page to mysql database and create a table of given... named 'usermaster' in mysql and create table "user_master". Create
Read Lines from text file
read from the text file and displays the output as desired. Unable to read the rest...Read Lines from text file  Here's a brief desc of what my Java code does .. I'm using BufferedReader to read lines from a text files and split each
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
How To Store HTML img Into The MySQL Using Java
How To Store HTML img Into The MySQL Using Java In this section you will read... jquery, Ajax, MySQL and we will create a JSP for writing the Java code... the image into the database using MySQL in Java. In this example I have created a JSP
How to store data entered by User in JSP page in XML file
  JSP store data entered by user into XML file 1)form.jsp: <html>...How to store data entered by User in JSP page in XML file  How to store data entered by user in JSP page to be saved in XML file.On clicking submit
Read data from excel file and update database using jsp
Read data from excel file and update database using jsp  read data from excel file and update database using jsp Hi, I am using a MySQL database for scientific research analysis. My team members sends research data in excel file
Read data again - Java Beginners
Read data again  Hey, i want to ask again about how to read data...), jab varchar(35), cab varchar(15), ket varchar(30) My data in txt file is://i... data from txt file and send to DB.i'm using one button to call.  Hi
How to read data from txt file and save to database MySql - Java Beginners
How to read data from txt file and save to database MySql  Please help me again ,my problem right know is how to read data from txt file then data... this. Thank's very much   Hi friend, code to read a file import
Java insert file data to JTable
Java insert file data to JTable In this section, you will learn how to insert text file data into JTable. Swing has provide useful and sophisticated set... with AbstractTableModel to inherit its methods and properties. Now we have read the file
How to Read a File in Java
// read via File Reader String data =""; // Read br and store a line...How to Read a File in Java? In this section we are going to know, How to read a file in Java. We have to follow three step to read a File. First get
convert data from pdf to text file - Java Beginners
convert data from pdf to text file   how to read the data from pdf file and put it into text file(.txt
retrieve data from mysql database and store it in a variable ?
retrieve data from mysql database and store it in a variable ?  sir , I am working on a project , in which I have to apply operation on input data... to store that data in int variable. how to do this ?   Here is an example
Read data again - Java Beginners
Read data again  OK my problem some like my first question.First i... varchar(15), cab varchar(15), ket varchar(30) then i have a data from txt file... Pusat; i want data from txt file save to database like my DB with one button.but
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... read data into database.So please give me some sample code. Thanks
Java read file
There are many ways to read a file in Java. DataInputStream class is used to read text File line by line. BufferedReader is also used to read a file in Java... BufferedReader class read text from a character-input stream rather than read one
uploading a text file into a database
uploading a text file into a database  how to upload a text file... = conn.prepareStatement("insert into myfile( file_name, file_data) values... { static File file; public static void main(String[] args) throws Exception
xl read
: Insert excel file data into database Read Excel File...xl read  hi, i have read excel sheet data using poi api and printed on console, now i have to store the same data which is printed on the console
how to store/retrieve doc file - Java Beginners
how to store/retrieve doc file  i want to wirte a code that stores/ retrieves .doc files to the mysql database using jsp pages... can anyone help me with the code?  Use this stuff inside your jsp page for store file
Write to a file
Write to a file       As we have read about  the BufferedOutputStream class that store the data in an internal buffer and lets you write
Read the File
Read the File     ... the data is read in form of a byte through the read( ) method. The read... ReadFilter This is a text file C:\nisha> Download
Data read. - XML
Data read.  How to store or read data in XML from Struts.Plz give me example. Thanx
Java Xml Data Store
be followed up and/or purchased. You will need to store the data in a local binary... the implementation needs to change later on (perhaps they might decide to store the data...Java Xml Data Store  I have to do this project and i'm finding it so
J2ME Read File
shows you how to read the data of the specified file. To implement this type.... In this application we are creating a "help.txt" file and read the data... J2ME Read File      
How to read text file in Servlets
How to read text file in Servlets  ... file in servlets. In this example we will use the input stream to read the text... it to the BufferedReader. A variable text is defined of String type. Read the file line
create login page using data from text file
create login page using data from text file  I want to create login page using data store in textfile(data submit from regiter page to textfile) using jsp and servlet. Thanks
how to store data in XML file - JSP-Servlet
how to store data in XML file  hi i have to store the data for example user id and password in a xml file the input userid and password will be coming from jsp middle ware servlet how to do that?   Hi friend
how to read text file in jtable in netbeans7.0
how to read text file in jtable in netbeans7.0  text file... want to displaythe above .txt file in jtable as following format having 3 columns contigID length size and then display sequence like "ATGCGSA..." in text
How I Upload File and Store that file name in Database using JSP
How I Upload File and Store that file name in Database using JSP  Hi All, I m the beginner in JSP and I want to upload the file and store that file and some other form data in MySQL database. Ex. There is one employee detail
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?  i have multiple(app..100) text... column value that keeps on changing for every file.i have read the data from all
Mysql Loader Control File
Mysql Loader Control File       Mysql Loader Control File is the mean to import a data to a plain text from Mysql database. Understand with Example The Tutorial
Mysql Loader Control File
Mysql Loader Control File       Mysql Loader Control File is the mean to import a data to a plain text from Mysql database. Understand with Example The Tutorial
Reading Text file and storing in map
Reading Text file and storing in map  Hi I have multiple text files. I want to read thoses files and store those records in map. Map will be of "LinkedHashMap<String, Map<String, String>>" type. Please let me know

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.