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

  • SEARCH
  • Home
  • 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 8815663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:26:05+00:00 2026-06-14T04:26:05+00:00

I am implementing an JAVA application which takes data from different URL’s and store

  • 0

I am implementing an JAVA application which takes data from different URL’s and store this data to a databse.Each table has it’s own collections of URL’s from which it receives the data. I am doing this by implementing a preparedstatement for each table, get data from the URL, bind data to preparestatement and adding data as a batch until all the URL’s for a table are finished. And then doing executeBatch on the prepare statement. I do have some 6-8 tables and each table has some 200 rows. I am doing the same procedure for each table but after updating 3-4 tables my executeBacth is thrwoing an exception which says :

 java.sql.SQLException: SQL Exception : [Microsoft][ODBC Driver
 Manager] Invalid string or buffer length   at
 sun.jdbc.odbc.JdbcOdbcPreparedStatement.setObject(JdbcOdbcPreparedStatement.java:1438)
    at
 sun.jdbc.odbc.JdbcOdbcPreparedStatement.setObject(JdbcOdbcPreparedStatement.java:1073)
    at
 sun.jdbc.odbc.JdbcOdbcPreparedStatement.emulateExecuteBatch(JdbcOdbcPreparedStatement.jjva:2104)
    at
 sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeBatchUpdate(JdbcOdbcPreparedStatement.java:1782)
    at
 sun.jdbc.odbc.JdbcOdbcStatement.executeBatch(JdbcOdbcStatement.java:911)
    at FaoClient.CFaoTable.InsertFromPartialSource(CFaoTable.java:174)

I have tested the same program by changing the order of fetching the data for tables but it is always throwing exception after inserting data 4-5 tables. I feel that it is like some memory leak situation but as I know JAVA grabage collector will never let this situaion happen. I am very new to this JAVA world so I might be wrong. I am pasting the part of my code which uses java.sql.* for purpose of inserting the records.

  private boolean BindValueToStmt(PreparedStatement ps, int index, TableCol.ColType type, String ColVal) {
        if ((ps == null) || (ColVal == "")) {
            return false;
        }
        try {
            switch (type) {
                case INTEGERT: {
                    ps.setInt(index, Integer.parseInt(ColVal));
                    return true;
                }
                case STRINGT: {
                    ps.setString(index, ColVal);
                    return true;
                }
                case REALT: {
                    ps.setFloat(index, Float.parseFloat(ColVal));
                    return true;
                }
                case DOUBLET: {
                    ps.setDouble(index, Double.parseDouble(ColVal));
                    return true;
                }
                default:
                    ps.setNull(index, java.sql.Types.NULL);
            }
            return true;
        } catch (SQLException E) {
            System.out.println("Error in Setting the value of the col in table: " + Name + E);
            E.printStackTrace();
            return false;
        }
    }



   private String CreatePreparedInsertStatement() {
        StringBuilder insertStmt = new StringBuilder("insert into " + Name + "(");
        String val = " values (";
        for (int index = 0; index < Columns.size(); index++) {
            TableCol col = Columns.get(index);
            if (index != Columns.size() - 1) {
                String Stmt = col.GetColName() + ", ";
                insertStmt.append(Stmt);
                val += "?, ";
            } else {
                String Stmt = col.GetColName() + ")";
                insertStmt.append(Stmt);
                val += "?)";
            }
        }
        insertStmt.append(val);
        return insertStmt.toString();
    }

And below is the code which is actually inserting the data.

  private boolean InsertFromPartialSource(Connection conn, SAXReader reader) {
        try {
            if (conn == null || reader == null) {
                return false;
            }
           //Some Code not realted to java.sql

            conn.setAutoCommit(false);
            String strPs= CreatePreparedInsertStatement();
            PreparedStatement ps = conn.prepareStatement(strPs);

            //Some Code not realted to java.sql

            for (int index = 0; index < Columns.size(); index++) {
                    TableCol col = Columns.get(index);
                    //Some Code not realted to java.sql
                    if (!BindValueToStmt(ps, index + 1, col.GetColType(), colVal)) {
                        ps.setNull(index + 1, TableCol.GetSqlColTypeFrmType(col.GetColType()));
                    }
                }
                rowCount++;
                System.out.println(rowCount + "rows has been extracted for table \" " + Name);
                ps.addBatch();

            }
            if (rowCount > 0) {
                int RecordsUpdated[] = ps.executeBatch();
            }
            conn.commit();
            conn.setAutoCommit(true);
            ps.close();
            return true;
}

I have only pasted the part of the function InsertFromPartialSource which is relevant to database update for clarity. Can someonw please indicate what things going wrong here?

The solution to above problem is:
Change your MySql Connector or Driver to MySqlJDBC driver. It can be
found on below link:
http://dev.mysql.com/downloads/connector/j/5.1.html

  • 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-14T04:26:06+00:00Added an answer on June 14, 2026 at 4:26 am

    Consider switching to the real JDBC driver for your database (if there is one). The JdbcOdbc bridge is rather bad, specific JDBC drivers usually work better.

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

Sidebar

Related Questions

I'm trying to code an application which runs un different java platforms like J2SE,
I have an application which consists of two activities/screens and a java class from
I'm implementing a little web application using Java and the Wicket framework. Each user
This question is related to Implementing logging in a Java application , but since
I am implementing the client side of some java application for Android devices which
I am implementing a java swing application which has a JPanel that serves as
(Using Java) I am implementing a generic class which is a B-Tree. When the
After searching for the answers to my questions Implementing logging in a Java application
I have a Java EE web application using features from the Java EE 6
Background: I have a Spring 2.5/Java/Tomcat application. There is the following bean, which is

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.