Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9220803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:26:02+00:00 2026-06-18T03:26:02+00:00

im trying to get the data from text file and insert in to mysql

  • 0

im trying to get the data from text file and insert in to mysql database..some of rows are successfuly inserted but when runing the program it shows this error message..

java.io.IOException: Read error
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:199)
at java.io.DataInputStream.read(DataInputStream.java:132)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at InsertDB.inserdata(InsertDB.java:53)
at InsertDB.main(InsertDB.java:96)

this is my program

 public class InsertDB {
    Connection conn ;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "dna";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "root"; 
    String password = "123";

    public void inserdata()
    {


      String[] RowItems = new String[11];
      int[] intRowItems=new int[10];
    try{
    conn = DriverManager.getConnection(url+dbName,userName,password);
     Statement st = conn.createStatement();
     // Open the file that is the first 
    // command line parameter
     FileInputStream fstream = new FileInputStream("result.txt");
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    StringTokenizer stringTokenizer ;





    while ((strLine = br.readLine()) != null) {
    stringTokenizer=new StringTokenizer(strLine);
   int j=0;
   while(stringTokenizer.hasMoreTokens()){
    RowItems[j]=stringTokenizer.nextToken();
    j++;
    }
   int c2,c3,c4,c5,c6,c7,c8,c9,c10,c11;

      c2=Integer.valueOf(RowItems[1]).intValue();
       c3=Integer.valueOf(RowItems[2]).intValue();
        c4=Integer.valueOf(RowItems[3]).intValue();
         c5=Integer.valueOf(RowItems[4]).intValue();
          c6=Integer.valueOf(RowItems[5]).intValue();
           c7=Integer.valueOf(RowItems[6]).intValue();
            c8=Integer.valueOf(RowItems[7]).intValue();
             c9=Integer.valueOf(RowItems[8]).intValue();
              c10=Integer.valueOf(RowItems[9]).intValue();
               c11=Integer.valueOf(RowItems[10]).intValue();

     String temp=RowItems[0];
    String insert="INSERT into protein_predicted                 VALUES('"+temp+"','"+c2+"','"+c3+"','"+c4+"','"+c5+"','"+c6+"','"+c7+"','"+c8+"','"+c9+"','      "+c10+"','"+c11+"')";
    st.executeUpdate(insert);

    in.close();
    }
    System.out.println("Insertted successfully");
     }
       catch (SQLException e) {
        throw new RuntimeException(e);
       }
       catch (Exception e){//Catch exception if any
        //System.err.println("Error: " + e.getMessage());
      e.printStackTrace();
      //Close the input stream



    }
    }
    public static void main(String args[])
    {
        InsertDB a=new InsertDB();
        a.inserdata();


    }

my text file contains multiple columns and multiple rows like this

1BG8A 76 33 0 18 1 0 1 5 2 16

please help me to slove this..thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:26:03+00:00Added an answer on June 18, 2026 at 3:26 am

    You are closing your DataInputStream inside of the while loop that is reading it. I would remove that in.close() line and outside of the while loop close your BufferedReader after you are done reading everything using br.close();

    If you are using Java 6 or below you would, ideally, declare the BufferedReader variable outside of the try…catch and add a finally clause to close the reader in case a read error happens. In Java 7 there’s an AutoCloseable interface that helps handle this automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert some e mails from a text file into MySQL
Using php I am trying to get some data from a .csv file which
I'm trying to load some data from a fixed width text file into a
I have a mysql database that I'm trying to populate from a text file.
I am trying to get some data from a database on the fly and
So I'm trying to get data from my sql database and sort it by
I am trying to get my data from a query string, but use it
I'm trying to get some data from a certain web-based api using the libcurl
I am trying to get data back from a PHP file assigned with GET
I'm trying to get some data from a table, where the tag has no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.