Help! Check data in MS Excel file(JDBC-ODBC)

Hi guys,
I wrote a program that can check data in MS Excel file.
User can input a sentence like "1->2" ,"1->3" (one determine one), then the program can find the data which violate the integrity constrains(functional dependency).For example, if we have the functional dependency "TSeq_gi->TSeq_accver", the program looks for two or more tuples with the same "TSeq_gi" value but the different "TSeq_accver" value in Excel file. These tuples violate the integrity constraint. But now,I can't figure out how to modify this program to multiple determine one. (like 1 3->5 or 1 3 4 5->7) . 1 3 ->5 means: look for 1 and 3 have same value but 5 different. I get stuck. Can some experts help me?
The code and Excel file are in below link. Download and play it! Thank you~~
Karen.
http://us.f1f.yahoofs.com/bc/665bbb4/bc/Java/code.zip?bf6cljAB_wgRYVQf
PS: You need to set up JDBC ODBC driver in MS windows "Administrative Tools" first. Data Souce name is Test .
Main logic class:
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
if (e.getActionCommand()=="SEARCH")
     try{
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     con1= DriverManager.getConnection("jdbc:odbc:Test");
     stmt2= con1.createStatement();
input1 = new String(pathTf.getText());     
     main_loop: while(true){
if (input1.equals("0")){     
          // break out of while(1)
          break main_loop;
     st= new StringTokenizer(input1," ,-=>");          
          while(st.hasMoreTokens()){
               // analyze the input stream.
               // Attention, the program didn't do the input value check.
               input1= st.nextToken();
               input2= st.nextToken();               
          query= "select "+ schema[Integer.parseInt(input1)-1]+ ","+ schema[Integer.parseInt(input2)-1]+ " from [Sheet1$]";     
          rs2= stmt2.executeQuery(query);     
          rowCounter= 0;
          list1.clear();
          list2.clear();
          list3.clear();
          while(rs2.next()){
               // increase the row counter
               rowCounter++;
               // initial the flag
               col1= rs2.getString(1);
               col2= rs2.getString(2);               
               // for the initalization
               if (list1.isEmpty()){
               list1.addElement(col1);
               list2.addElement(col2);
               row="Row 2";
               list3.addElement(row);     
               // compare weather exist dependance
               else
               for (int i=0;i<list1.size();i++){
                    // if col1 match with the first part of value in the list
                    if (((String)list1.get(i)).equals(col1)){
                         // The independence pair match
                         if (((String)list2.get(i)).equals(col2)){
                              break;
                         else
                              textArea.append("\n"+"Violate Integrity Constraints Found : "+" Row "+ (rowCounter+1)+ " not match with "+ list3.get(i)+".");
                              System.out.println("\n"+" Row "+ (rowCounter+1)+ " not match with "+ list3.get(i)+".");      
                              break;                    
                    // if col1 not match with any value, add a new record in list
                    else
                         list1.addElement(col1);
                         list2.addElement(col2);
                         row="Row "+ (rowCounter+1);
                         list3.addElement(row);
               }// end of for
               }//end of else
}//end of while
}//end of while(1): main_loop
     }catch(Exception ex){
     //System.err.println(ex);

sorry~~I am new here!
class MyActionListener implements ActionListener{
         public void actionPerformed(ActionEvent e){
              if (e.getActionCommand()=="SEARCH")
             try{
                      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                      con1= DriverManager.getConnection("jdbc:odbc:Test");
                      stmt2= con1.createStatement();
                      input1 = new String(pathTf.getText());
         main_loop: while(true){
                 if (input1.equals("0")){
                             // break out of while(1)
                 break main_loop;
                  st= new StringTokenizer(input1," ,-=>");
                 while(st.hasMoreTokens()){
                              // analyze the input stream.
                                 input1= st.nextToken();
                                 input2= st.nextToken();
                      query= "select "+ schema[Integer.parseInt(input1)-1]+ ","+ schema[Integer.parseInt(input2)-1]+ " from [Sheet1$]";
                 rs2= stmt2.executeQuery(query);
                 rowCounter= 0;
                 list1.clear();
                 list2.clear();
                 list3.clear();
                while(rs2.next()){
                       // increase the row counter
                rowCounter++;
                       // initial the flag
                col1= rs2.getString(1);
                col2= rs2.getString(2);
                       // for the initalization
                  if (list1.isEmpty()){
                      list1.addElement(col1);
                       list2.addElement(col2);
                        row="Row 2";
                      list3.addElement(row);
                    // compare weather exist dependance
                       else
                          for (int i=0;i<list1.size();i++){
                            // if col1 match with the first part of value in the list
                                 if (((String)list1.get(i)).equals(col1)){
                          // The independence pair match
                 if (((String)list2.get(i)).equals(col2)){
                     break;
                          else
            textArea.append("\n"+"Violate Integrity Constraints Found : "+" Row "+ (rowCounter+1)+ " not    match    with "+ list3.get(i)+".");
           System.out.println("\n"+" Row "+ (rowCounter+1)+ " not match with "+ list3.get(i)+".");
                        break;
                      // if col1 not match with any value, add a new record in list
                        else
                             list1.addElement(col1);
                             list2.addElement(col2);
                             row="Row "+ (rowCounter+1);
                             list3.addElement(row);
                   }// end of for
               }//end of else
           }//end of while
        }//end of while(1): main_loop
                             }catch(Exception ex){
                                 //System.err.println(ex);
                                 }

Similar Messages

  • Help! How to read data from an Excel file?

    Hi,
    I need to read data from an Excel file that may contain more then one table in a sheet. How can I read them?
    I would be eternally grateful to anyone who can give me any information.

    Did you try POI from Apache?
    http://jakarta.apache.org/poi/index.html

  • How to retrieve data from an Excel file which is located on server

    hi everybody,
                    I am using SAP NWDS 2004s .     
                I have done an application on how to export the table data into an Excel .
    Now i want to get the data from an Excel file which is located in server and display that data which is in excel in a View for example a Sample view in Webdynpro  .
    In Sample view i took a uielement textview to display the data ....   
    can any one help how to procced further
    Thanks in advance
    Madhavi

    Options to read Excel data to WebDynpro context
    Reading Excel Sheet from Java without using any Framework
    Reading Multiple Sheets of Excel Sheet from Java
    Few Threads
    How to Display the content of Excel file into Webdynpro Table
    Is it possible to upload data from excel file(.xls)
    Re: How to export the data as integer into excel sheet?
    regards
       Vinod

  • Reading data from an excel file

    Hi,
    I want to read data from the excel file and display it in
    jsp page. Iam getting the following error:
    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con =
    DriverManager.getConnection("jdbc:odbc:mydsn","","");
    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery("select * from [holidays$]");
    Here i have created the dsn with the name "mydsn". I have the
    following data in the mydsn.dsn file:
    [ODBC]
    DRIVER=Microsoft Excel Driver (*.xls)
    UID=admin
    UserCommitSync=Yes
    Threads=3
    SafeTransactions=0
    ReadOnly=1
    PageTimeout=5
    MaxScanRows=8
    MaxBufferSize=2048
    FIL=excel 8.0
    DriverId=790
    DefaultDir=D:\WorkSpace\Projects\VINET\devl\webroot\jsp
    DBQ=D:\WorkSpace\Projects\VINET\devl\webroot\jsp\list_of_holidays_2003.xls
    thanks in advance
    phani.

    You might want to look at the POI project (an open source Jakarta sub-project) that allows you to create/modify/read excel files via Java code. That might be more flexible and easier than what you're currently trying to do.
    Cheers

  • How to read data from the excel file using java code.

    Hi to all,
    I am using below code to getting the data from the excel file but I can't get the corresponding data from the specific file. can anyone give me the correct code to do that... I will waiting for your usefull reply......
    advance thanks....
    import java.io.*;
    import java.sql.*;
        public class sample{
                 public static void main(String[] args){
                      Connection connection = null;
                          try{
                               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                               Connection con = DriverManager.getConnection( "jdbc:odbc:Mydsn","","" );
                               Statement st = con.createStatement();
                               ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );
                               System.out.println("sample:"+rs);
                                  ResultSetMetaData rsmd = rs.getMetaData();
                                  System.out.println("samplersd:"+rsmd);
                               int numberOfColumns = rsmd.getColumnCount();
                                  System.out.println("numberOfColumns:"+numberOfColumns);
                                   while (rs.next()) {
                                            System.out.println("sample1:"+rs);
                                            for (int i = 1; i <= numberOfColumns; i++) {
                                                 if (i > 1) System.out.print(", ");
                                                 String columnValue = rs.getString(i);
                                                 System.out.print(columnValue);
                                            System.out.println("");
                                       st.close();
                                       con.close();
                                      } catch(Exception ex) {
                                           System.err.print("Exception: ");
                                           System.err.println(ex.getMessage());
                        }

    1: What is the name of the excel sheet?
    2: What is printed in this program? null ? anything?
    error?Excel file name is "sample.xls" I set excel file connectivity in my JDBC driver(DSN). Here in my program I am not giving that excel file name. I am giving only that excel sheet name. that is followed
    ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );The output of this program is given bellow.
    sample:sun.jdbc.odbc.JdbcOdbcResultSet@1b67f74
    samplersd:sun.jdbc.odbc.JdbcOdbcResultSetMetaData@530daa
    numberOfColumns:2

  • [Forum FAQ] How do I export each group data to separated Excel files in Reporting Services?

    Introduction
    There is a scenario that a report grouped by one field for some reasons, then the users want to export each group data to separated Excel files. By default, we can directly export only one file at a time on report server. Is there a way that we can split
    the report based on the group, then export each report to Excel file?
    Solution
    To achieve this requirement, we can add a parameter with the group values to filter the report based on the group, then create a data-driven subscription for the report which get File name and parameter from the group values.
    In the report, create a parameter named Name which use the Name field as Available Values (supposing the group grouped on Name field).
    Add a filter as below in the corresponding tablix:
    Expression: [Name]
    Operator: =
    Value: [@Name]
    Deploy the report. Then create a data-driven subscription with Windows File Share delivery extension for the report in Report Manager.
    During the data-driven subscription, in the step 3, specify a query that returns the Name field with the values as the group in the report.
    In the step 4 (Specify delivery extension settings for Report Server FileShare), below “File name”option, select “Get the value from the database”, then select Name field.
    Below ‘Render Format’ option, select Excel as the static value.
    In the step 5, we can configure parameter Name “Get the value from the database”, then select Name field. 
    Then specify the subscription execute only one time.
    References:
    Create a Data-Driven Subscription
    Windows File Share Delivery in Reporting Services
    Applies to
    Reporting Services 2005
    Reporting Services 2008
    Reporting Services 2008 R2
    Reporting Services 2012
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thanks,
    Is this a supported scenario, or does it use unsupported features?
    For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
    in a supported way?
    Thanks! Josh

  • Report data download to excel file

    Hi experts,
       My requirement is report data download to excel file and that file should be an attachment to send email to specified people.
    first i want to to download data to excel file and that file should be an attachment.
    Regards
    V.Venu

    Hi venu,
    Before posting the question, just search for the related query, more number of post has been posted related to your query,
    any ways  check this below links, it will solve your problem.
    <<linkfarm removed>>
    Cheers
    NZAB
    Edited by: kishan P on Jan 10, 2012 4:51 PM

  • FM to upload data / Attribute in EXCEL File in SRM7.0

    Hi Experts,
    We  had used FM BBP_UPDATE_ATTRIBUTE to upload Storage Location( LAG) attribute in SRM ORG Structure and other data in other case ...... Currently we arranged to upload the .TXT file.
    But we want to upload from MS EXCEL File.
    Can anyone please suggest, which FM we can need to use  to upload data from MS EXCEL File.
    Thnaks
    NAP

    Hi Narenrda,
    Normally in ECC we can use the FM "ALSM_EXCEL_TO_INTERNAL_TABLE" to convert excel to internal table but this FM is not there in SRM 7.0 .
    I copied the above mentioned FM along with global data and includes of the function group from ECC and it works fine in SRM.
    You can use the FM "BBPU_FILENAME_HELP" to show an F4 help for the input field for selecting a file from desktop.
    Thanks,
    Anubhav

  • How to export the data from an excel file to Oracle database by using macro

    Hi,
    I want to export data from an excel file into Oracle database.There is one method that by creating the macros through excel we are able to do this.
    can anybody please send me the code to create macros?
    Thanks in advance.
    Regards,
    Surendra.V

    There are several resources on the web, but you could start analyzing if this code fits your needs --> VBA Macro for Excel 2003 Export of Text File with Comma and Quote Delimiters.
    ~ Madrid

  • GUI_UPLOAD to read data from an Excel File

    Hi Folks,
    I'm using FM GUI_UPLOAD to read data from an Excel File. But all I see in the table returned is 1 row with garbage values (special chacaters). Excel Workbook has proper data in the sheet, but its not getting uploaded properly. Sy-subrc is 0.
    What could be the reason?
    Thanks

    use FM : ALSM_EXCEL_TO_INTERNAL_TABLE
    See the example program to get from XLS file to Internal table
    REPORT ZLWMI151_UPLOAD no standard page heading
                           line-size 100 line-count 60.
    *tables : zbatch_cross_ref.
    data : begin of t_text occurs 0,
           werks(4) type c,
           cmatnr(15) type c,
           srlno(12) type n,
           matnr(7) type n,
           charg(10) type n,
           end of t_text.
    data: begin of t_zbatch occurs 0,
          werks like zbatch_cross_ref-werks,
          cmatnr like zbatch_cross_ref-cmatnr,
          srlno like zbatch_cross_ref-srlno,
          matnr like zbatch_cross_ref-matnr,
          charg like zbatch_cross_ref-charg,
          end of t_zbatch.
    data : g_repid like sy-repid,
           g_line like sy-index,
           g_line1 like sy-index,
           $v_start_col         type i value '1',
           $v_start_row         type i value '2',
           $v_end_col           type i value '256',
           $v_end_row           type i value '65536',
           gd_currentrow type i.
    data: itab like alsmex_tabline occurs 0 with header line.
    data : t_final like zbatch_cross_ref occurs 0 with header line.
    selection-screen : begin of block blk with frame title text.
    parameters : p_file like rlgrap-filename obligatory.
    selection-screen : end of block blk.
    initialization.
      g_repid = sy-repid.
    at selection-screen on value-request for p_file.
      CALL FUNCTION 'F4_FILENAME'
           EXPORTING
                PROGRAM_NAME = g_repid
           IMPORTING
                FILE_NAME    = p_file.
    start-of-selection.
    Uploading the data into Internal Table
      perform upload_data.
      perform modify_table.
    top-of-page.
      CALL FUNCTION 'Z_HEADER'
      EXPORTING
        FLEX_TEXT1       =
        FLEX_TEXT2       =
        FLEX_TEXT3       =
    *&      Form  upload_data
          text
    FORM upload_data.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           EXPORTING
                FILENAME                = p_file
                I_BEGIN_COL             = $v_start_col
                I_BEGIN_ROW             = $v_start_row
                I_END_COL               = $v_end_col
                I_END_ROW               = $v_end_row
           TABLES
                INTERN                  = itab
           EXCEPTIONS
                INCONSISTENT_PARAMETERS = 1
                UPLOAD_OLE              = 2
                OTHERS                  = 3.
      IF SY-SUBRC <> 0.
        write:/10 'File '.
      ENDIF.
      if sy-subrc eq 0.
        read table itab index 1.
        gd_currentrow = itab-row.
        loop at itab.
          if itab-row ne gd_currentrow.
            append t_text.
            clear t_text.
            gd_currentrow = itab-row.
          endif.
          case itab-col.
            when '0001'.
              t_text-werks = itab-value.
            when '0002'.
              t_text-cmatnr = itab-value.
            when '0003'.
              t_text-srlno = itab-value.
            when '0004'.
              t_text-matnr = itab-value.
            when '0005'.
              t_text-charg = itab-value.
          endcase.
        endloop.
      endif.
      append t_text.
    ENDFORM.                    " upload_data
    *&      Form  modify_table
          Modify the table ZBATCH_CROSS_REF
    FORM modify_table.
      loop at t_text.
        t_final-werks = t_text-werks.
        t_final-cmatnr = t_text-cmatnr.
        t_final-srlno = t_text-srlno.
        t_final-matnr = t_text-matnr.
        t_final-charg = t_text-charg.
        t_final-erdat = sy-datum.
        t_final-erzet = sy-uzeit.
        t_final-ernam = sy-uname.
        t_final-rstat = 'U'.
        append t_final.
        clear t_final.
      endloop.
      delete t_final where werks = ''.
      describe table t_final lines g_line.
      sort t_final by werks cmatnr srlno.
    Deleting the Duplicate Records
      perform select_data.
      describe table t_final lines g_line1.
      modify zbatch_cross_ref from table t_final.
      if sy-subrc ne 0.
        write:/ 'Updation failed'.
      else.
        Skip 1.
        Write:/12 'Updation has been Completed Sucessfully'.
        skip 1.
        Write:/12 'Records in file ',42 g_line .
        write:/12 'Updated records in Table',42 g_line1.
      endif.
      delete from zbatch_cross_ref where werks = ''.
    ENDFORM.                    " modify_table
    *&      Form  select_data
          Deleting the duplicate records
    FORM select_data.
      select werks
             cmatnr
             srlno from zbatch_cross_ref
             into table t_zbatch for all entries in t_final
             where werks = t_final-werks
             and  cmatnr = t_final-cmatnr
             and srlno = t_final-srlno.
      sort t_zbatch by werks cmatnr srlno.
      loop at t_zbatch.
        read table t_final with key werks = t_zbatch-werks
                                    cmatnr = t_zbatch-cmatnr
                                    srlno = t_zbatch-srlno.
        if sy-subrc eq 0.
          delete table t_final .
        endif.
        clear: t_zbatch,
               t_final.
      endloop.
    ENDFORM.                    " select_data

  • Can I recover my data information from excel file?

    For any reason I already lost (clear all) my data information, have any option where import the data information from excel file to view responses sheet? or , how, can I recover my data information?
    Antonio

    If you had saved your Excel file, then you may revert the Excel file to the last saved version. Follow below steps to do this:
    On the File tab, click Open.
    Double-click the name of the file that you have open in Excel.
    Click Yes to reopen the Excel file.
    If you had not saved Excel file, then follow below steps to recover your file.
    Click the File tab.
    Click Recent.
    Click Recover Unsaved Workbooks.

  • How do read the data of the excel file line by line to the waveform?

    hello:
          i am a beginner.so i hope that  you can give me a small example。the data of the excel  file i
     have given out.
    looking for your replys!!!
    Solved!
    Go to Solution.
    Attachments:
    数据.xls ‏14 KB

    try this. best of luck
    Gaurav k
    CLD Certified !!!!!
    Do not forget to Mark solution and to give Kudo if problem is solved.
    Attachments:
    Read column.zip ‏26 KB

  • Problem in scheduling data refresh of excel file that uses PowerPivot

    I think I have successfully created and enabled the gateway and data sources for refresh - they are both seeming to connect.  However, when I try to schedule a data refresh to occur in the PowerBI site for the Excel file I receive an error message
    that the connection could not be established and receive error message "Correlation ID: d118ab93-436d-44a9-8c09-564f64fe0c58".  Appreciate any assistance in figuring out how to resolve.  Thanks a lotl

    Let's track it here: https://social.technet.microsoft.com/Forums/en-US/42c806dc-2d82-4bcf-ab6e-c279e2692a68/problem-in-scheduling-data-refresh-of-excel-file-that-uses-powerquery-and-powerquery?forum=powerbiforoffice365 
    Ed Price, Azure & Power BI Customer Program Manager (Blog,
    Small Basic,
    Wiki Ninjas,
    Wiki)
    Answer an interesting question?
    Create a wiki article about it!

  • Loading data from an excel file to Oracle Tables

    Hi Everyone,
    Once again I will have to bring some data from some excel file, which I have already done and "know" how to do and I would like to confirm with you all something first.
    What I shall do is the following:
    From one excel workbook file which has a lot of info just in one spread sheet feed some tables with the data coming from it.
    So what I have though is create mane name ranges (Define names on excel) as I need and work with them, but I will be facing with headers on the rows and columns. There is where I doubt if it will be possible. So far, I will not be able to modify the Excel’s file structure.
    Something more or less like this:
    Country1 Country 2
    Sales1 9999999 9999999
    Sales2 9999999 9999999
    Sales3 9999999 9999999
    Total123 9999999 9999999
    Sales4 9999999 9999999
    Sales5 9999999 9999999
    Sales6 9999999 9999999
    Total456 9999999 9999999
    Best regards.
    Jaison

    Hi SH,
    First of all, I do really appreciate your time, patience and guidance.
    Ok, let me get this straight.
    You will need to create a data server for each Excel Work book
    That means that as I will just work with one excel sheet, I will just have one data server and within it, there will be the spread sheets (excel tabs) and therefore the different named ranges.
    Each of your named ranges will be a data store beneath the data server which can be used as a source model in your ODI interfaces. Therefore if you have a single workbook with 12 sheets for the months, each covered by a single named range, you would have a single data server withe 12 data stores.
    This means that I will have something like this:
    + “My_Workbook.xls” server name (Just one)
    -     Spread sheet 1 (1 or several named ranges)
    -     Spread sheet 2 (1 or several named ranges)
    -     Spread sheet 3 (1 or several named ranges)
    -     Spread sheet n (1 or several named ranges)
    I do think that if my statement above is correct, I think I got the idea. Is it like that?
    I have gotten another question; let’s say for example that in any spread sheet I will have three different named ranges. The difference between spread sheet and spread sheet will be the month within and of course the information. Would it be accurate to bring it like that? That means that so far for twelve month I will bring 36 named ranges.
    Well I think I had explained myself. Please do not hesitate to contact me if any further detail is required.
    Best regards.
    J

  • Binding data from an Excel file

    Need to have this done like yesterday!  Pressure is on.
    I need to be able to bind an Excel file to my form.  I want to be able to use the data in my Excel file to populate my drop down lists in my form.
    Question: 1.  Can I do this?
    Question: 2   Does the Excel file need to be formatted a certain way?
    Question: 3  Will this work with a user using only Adobe Reader?
    Any assistance given will be greatly appreciated.  Desparate!!!!

    Easiest way is to use the File/SaveAs option in Excel to save the spreadsheet as a comma-delimited file.
    Then you can use any number of tools to import the comma-delimited file into a database table.
    Oracle provides the SQL-Loader tool:
    http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a76955/ch03.htm#2436
    Other tools like TOAD and PowerBuilder will also let you import comma delimited files

Maybe you are looking for

  • How to install Oracle FM Forms 11g on client system.

    Problem 1. I have an weblogic server installed on a server, now i have to install oracle Forms 11g in client system. its ask me weblogic server path whatever i try, its ask weblogic on client. what is the solution how installation of Oracle 11g form

  • ITunes Library.itl corrupt

    iTunes Library.itl corrupt. This is what i get when i open my itunes from this afternoon. i have instaled and removed and reinstatled itunes at least 3-4 times and still happens and also have run a chkdsk check more than once and it still comes up. c

  • Screen cut off

    Hi, since upgrading to 4.1 having loads of problems which I was just about to deal with but I've just noticed something else now, the top line of info is half cut off and if I then touch on i.e. the phone button at the bottom and then the home button

  • Help with encrypted mail!

    Hi, I'm trying to build a tool to send mail but when I run the program a "E-mail Scanner window" pops up with this message: "An encrypted email connection has been detected" and I can't send the mail. Once I've closed this window appears this message

  • 9i and 10g ODBC client

    Hello. I have a client that has an issue with ODBC connections. They had the 9i Oracle client installed already on the desktop. 10g client was then installed. Once 10g client was installed they can no longer connect to the 9i instance but they are ab