Results 1 to 7 of 7

Thread: ODBC connection to MS Excel file

  1. #1
    Join Date
    Jan 2010
    Posts
    3

    ODBC connection to MS Excel file

    hi,

    i am new to java programming. i need to read the contents of MS Excel file using ODBC Driver.
    i cannot use a DSN connection. i have written the following code to establish a DSNLess connection.

    String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
    String excel_path="C:\\employee.xls";
    String Connection_str="jdbc:odbcriver={Microsoft Excel Driver(*.xls)};DBQ="+ excel_path +";DriverID=22;READONLY=false;";

    try {
    Class.forName(driverName);
    Connection con = DriverManager.getConnection(Connection_str,"","");
    } catch (SQLException e) {....

    but i get the exception
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)


    could someone please help me.......



    Thanks,
    Lakshmi

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: ODBC connection to MS Excel file

    String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
    String excel_path="C:\\employee.xls";
    String Connection_str="jdbc:odbcriver={Microsoft Excel Driver(*.xls)};DBQ="+ excel_path +";DriverID=22;READONLY=false;";

    try {
    Class.forName(driverName);
    Connection con = DriverManager.getConnection(Connection_str,"","");
    } catch (SQLException e) {....
    This is your coding. And you have not mentioned the excel_path value in proper way. That is why you are getting this exception error.
    String excel_path="C:\\employee.xls";
    This must be as
    Code:
    String excel_path="C:/employee.xls";
    Do this change and execute your program. You would not get any error.

  3. #3
    Join Date
    Jan 2010
    Posts
    3

    Re: ODBC connection to MS Excel file

    i have tried bothe ways. i get the same exception whether i use "/" or "\\"

  4. #4
    Join Date
    Apr 2008
    Posts
    471

    Re: ODBC connection to MS Excel file

    This error can get generated if you have not created the Data-source properly. Follow the steps to create the data source :
    • Click on the start button and then open the Control Panel.
    • In Control Panel you will find the Administrative Tools.
    • Go in that and select the option Data Source ODBC.
    • Then click on the User DSN.
    • After clicking on that click on the add.
    • Then select the Driver Do Microsoft Access.
    • After this click on select and Browse the .mdb file(your access file) and clicked then click OK.
    Hope that your error will be fixed after creating the Data Source.

  5. #5
    Join Date
    Jan 2010
    Posts
    3

    Re: ODBC connection to MS Excel file

    ODBC connection with the DSN works fine. but i cannot use it for the application. i need to establish a DSNLess connection. i.e., i cannot expect users of my tool to go add DSN manually in the Control Panel giving exactly the name i have mentioned in the code. i need a DSNLess connection.

  6. #6
    Join Date
    Mar 2011
    Posts
    1

    Re: ODBC connection to MS Excel file

    Hi Lakshmi
    Did u get a solution for DSNless connection to excel?Pl. mail me at kattu.pune@gmail.com

  7. #7
    Join Date
    Jan 2006
    Posts
    605

    Re: ODBC connection to MS Excel file

    Quote Originally Posted by karthika View Post
    Hi Lakshmi
    Did u get a solution for DSNless connection to excel?Pl. mail me at kattu.pune@gmail.com
    I think that in Excel VBA, you could set it up via a connection. I have just never used (that I'm aware of) the type connections you're talking about but I would wonder if it will work via an ADODB connection. In any case you can get a direct reference from microsoft article here - http://support.microsoft.com/kb/165866

Similar Threads

  1. No ODBC Drivers available for Excel or Access in Windows 7
    By Mahican in forum Networking & Security
    Replies: 7
    Last Post: 01-11-2011, 12:59 PM
  2. Replies: 4
    Last Post: 13-02-2011, 10:37 AM
  3. How to make odbc connection force to close
    By Rixwel in forum Software Development
    Replies: 3
    Last Post: 13-08-2009, 09:39 AM
  4. Replies: 4
    Last Post: 07-05-2009, 02:09 PM
  5. Linking MS Project to MS Excel - ODBC Connection
    By manishdk in forum Microsoft Project
    Replies: 3
    Last Post: 19-12-2008, 07:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,291,805.16283 seconds with 17 queries