View Poll Results: poll me

Voters
1. You may not vote on this poll
  • How to solve this problem

    1 100.00%
  • this is best way to do this

    1 100.00%
Multiple Choice Poll.
Results 1 to 5 of 5
  1. #1
    zuzi is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default Read (using Odbc)and write using (POI api)

    Hi ALL,
    I tried to to read and write the data through excel files.But i am facing some issues while reading and writting the data.The exceptions which are coming are mentioned below
    __________________________________________________ _________________________________
    Exception:

    sqlselect 'villno','fno','w_name', 'age','idno','adcode','caste','educ','height' from [studyhb$]
    java.sql.SQLException: Column not found
    at sun.jdbc.odbc.JdbcOdbcResultSet.findColumn(Unknown Source)roundSQL
    select `month1`,`year1`,`round1`, `ttab1`,`teat1`,`m_wt1`,`m_pre1`, `eff11`,`eff12`,`eff13`,`hedu1`,`other1` from [studyhb$] where villno='' and fno='' and w_name='' and idno=''

    at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
    at db.ReadOdbc.WriteFirstRowOfInputSheet(ReadOdbc.jav a:283)
    at db.ReadOdbc.main(ReadOdbc.java:66)
    java.sql.SQLException: Column not found
    at sun.jdbc.odbc.JdbcOdbcResultSet.findColumn(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
    at db.ReadOdbc.GetSQLString(ReadOdbc.java:240)
    at db.ReadOdbc.WriteFirstRowOfInputSheet(ReadOdbc.jav a:300)
    at db.ReadOdbc.main(ReadOdbc.java:66)
    java.sql.SQLException: [Microsoft][ODBC Excel Driver] Data type mismatch in criteria expression.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unkno wn Source)
    at db.ReadOdbc.WriteFirstRowOfInputSheet(ReadOdbc.jav a:305)
    at db.ReadOdbc.main(ReadOdbc.java:66)
    java.lang.NullPointerException
    __________________________________________________ _______________________________

    I want that the data i am reading should be wriiten in excellsheet(output).The write file is now writting only headers.
    Please guide me how to do this
    Attached Files Attached Files

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Java Code:
    java.sql.SQLException: [Microsoft][ODBC Excel Driver] Data type mismatch in criteria expression.
    That means that one of these
    Java Code:
    where villno='' and fno='' and w_name='' and idno=''
    is probably a number field and not a text field (and they would have to be a text field in order to match a text criteria of ''.

  3. #3
    zuzi is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    Hi masijade,

    all fields are define as a string but still i m facing same issue

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default

    My solution would be...don't treat Excel as a database.
    It isn't.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by zuzi View Post
    Hi masijade,

    all fields are define as a string but still i m facing same issue
    Do they actually contain strings, or do they contain numbers. If they contain numbers then the ODBC driver will treat them number fields even if you used the cell formatting to tell excel to display numbers as strings. And, if a column contains both numbers in some cells and strings in other cells, then the ODBC driver will determine the type based on which is more populous. IOW, as mentioned before, do not treat excel as a DB, unless you are aware of the problems and know that that sheet won't trigger any of them (and there are a lot of possible triggers).

Similar Threads

  1. XML read/write in Java
    By bogdy.laurentiu in forum XML
    Replies: 5
    Last Post: 05-31-2010, 06:08 PM
  2. Read/Write Files
    By FlyNn in forum New To Java
    Replies: 3
    Last Post: 02-06-2010, 08:45 PM
  3. How to read/write txt in Java
    By megalomitis in forum New To Java
    Replies: 2
    Last Post: 11-13-2009, 10:09 AM
  4. How to read first 9 bytes and write in...?
    By aRTx in forum New To Java
    Replies: 8
    Last Post: 03-26-2009, 02:54 PM
  5. Read and Write file
    By mrdestroy in forum New To Java
    Replies: 13
    Last Post: 10-31-2008, 12:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •