Read database-writeExcel-readExcel-Write database table

package datamigration;
import java.sql.*;
import java.io.*;
import java.io.IOException;
import jxl.*;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.read.biff.BiffException;
public class NewExcel {
//In the following method we will be reading the Table from the Database and write it in an Excel File
public void getDataAndWrite() throws ClassNotFoundException, SQLException, WriteException, IOException {
Connection conn = null; //Manages connection
Statement stmt = null; //Query statement
ResultSet rs = null;
final String driver = "oracle.jdbc.driver.OracleDriver";
final String url = "jdbc:oracle:thin:@inbgewdrnd90hfm:1521:VISUAL"; //This URL will be specific to your Database
WritableWorkbook workbook = null;
workbook = Workbook.createWorkbook(new File("C:\\NewExcel2.xls")); //Again the name of file and its location will be your own
Class.forName(driver);
conn = DriverManager.getConnection(url, "visual", "visual");
stmt = conn.createStatement();
System.out.println("Executing query...");
rs = stmt.executeQuery("select * FROM TRANSACTION"); //the query is selecting everything from TRANSACTION table
WritableSheet sheet = workbook.createSheet("first sheet", 0);
Label FULLTEXT = new Label(0, 0, "FULLNAME");
sheet.addCell(FULLTEXT);
if (rs != null) {
int i = 0;
while (rs.next()) {
i++; //the counter
Label NAMEFULL = new Label(0, i, rs.getString(1)); //getting the values from the Table and appending them in TEXTFULL column
sheet.addCell(TEXTFULL); //adding column to Sheet
workbook.write();
workbook.close();
//Reading the Excel file
public void read(String inputFile) throws IOException, BiffException, ClassNotFoundException, SQLException {
Connection conn = null; //Manages connection
Statement stmt = null; //Query statement
ResultSet rs = null;
final String driver = "oracle.jdbc.driver.OracleDriver";
final String url = "jdbc:oracle:thin:@INBGEWDRND90Hgf:1521:wsa";
Class.forName(driver);
conn = DriverManager.getConnection(url, "corpus", "corpus");
stmt = conn.createStatement();
File inputWorkbook = new File(inputFile);
Workbook w;
w = Workbook.getWorkbook(inputWorkbook);
if (Workbook.getWorkbook(inputWorkbook) != null) {
System.out.println("Got the workbook" + "\n");
} else {
System.out.println("No workbook to print");
//Get the first sheet from the input file which is set earlier
Sheet sheet = w.getSheet(0);
//Set the for loop for reading the rows
for (int i = 0; i < sheet.getRows(); i++) {
String verbatim = sheet.getCell(0, i).getContents();
verbatim = verbatim.replaceAll("'", "''"); //"'" was causing an error so it was handled through"'"
verbatim = verbatim.replaceAll("&", "\\&");
String query = "insert into TRANSACTION (FULLNAME) values ('" + verbatim + "' )";
System.out.println(query);
stmt.executeUpdate(query);
public static void main(String[] args) throws ClassNotFoundException, WriteException, SQLException, IOException, BiffException {
NewExcel migratedata = new NewExcel();
migratedata.getDataAndWrite();
migratedata.read("C:\\NewExcel2.xls");
}

1.) Please make sure that your code is readable (use the CODE button)
2.) What is your question?
3.) Please read [How To Ask Questions The Smart Way|http://www.catb.org/~esr/faqs/smart-questions.html]

Similar Messages

  • FM to read Database table

    Hi,
    Is there any FM to read values from database table. I can do it by writing select query but I want to do it through an FM .
    Please help me.
    Thanks,
    Sravanthi

    >
    Sravanthi Palepu wrote:
    > Is there any FM to read values from database table. I can do it by writing select query but I want to do it through an FM .
    Why do you want to do so? Is it like you hate SELECT statements?
    @Mahesh: Is it easy(& also performance efficient) to write a SELECT stmt or use RFC_GET_TABLE_ENTRIES(where you have no filter to select data) to select data ?
    Suhas

  • Reg. reading database tables.

    Hi,
    I have stored some database table names in a custom table. In my custom report, I have to read those database tables depending on certain criteria.
    For ex: I have the table names 'MARA' , 'MARC' stored in my custom table ztables.
    In my report, if a flag is set to 'X', I have to read MARA otherwise MARC...(these entries in ztables can change in future..so i can not read directly from MARA or MARC)..How to achieve this? Once the table names are stored in a variable, how to read data from this table name? if i say 'read' it will try to read this variable and not the table.
    Thanks in advance for your input.

    you can try this approach
    data : ref_table_des type ref to cl_abap_structdescr.
    data:tabname like dd02l-tabname.
    data : idetails type abap_compdescr_tab,
           xdetails type abap_compdescr,
        xfc type lvc_s_fcat,
        ifc type lvc_t_fcat.
    data: dy_table type ref to data,
        dy_line  type ref to data,
    field-symbols: <dyn_table> type standard table,
                 <dyn_wa>.
      ref_table_des ?=
          cl_abap_typedescr=>describe_by_name( tabname ).
      idetails[] = ref_table_des->components[].
      loop at idetails into xdetails.
        clear xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
      endloop.
      call method cl_alv_table_create=>create_dynamic_table
                     exporting
                        it_fieldcatalog = ifc
                     importing
                        ep_table        = dy_table.
      assign dy_table->* to <dyn_table>.
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
    select *
    into table <dyn_table>
    from  (tabname).
    where variable tabname stores the name of the table stored in your custom table.

  • Using the Borland Database Engine to read AND write SHARED Paradox Database Tables

    I need to read and write Paradox database tables with a C# AT THE SAME TIME AS people using the Paradox tables with legacy Paradox programs interactively.
    I think the only way to do that reliably without corrupting the tables is to use the BDE Borland Database Engine.
    Does anyone know how to do that? I found this c++ program... But I don't know how to integrate this into c#
    http://www.codeproject.com/KB/database/bdedatabase.aspx
    Is there another way to do this? Again, most important, I don't want to corrupt the paradox database.
    I can read the paradox records all day long, that is no problem, it is updating at the same time as the legacy program users..
    I also know that the whole thing needs to be updated, but that can not be done overnight.
    Thanks in advance
    Dave

    Being pretty new to programming, I am trying just to read info from Paradox tables with C#. Info is actively being updated from another program at the same time. The program I am trying to write only needs to read data. The other program does use the BDE,
    so it is already present running on the computer.
    I've been looking at code but just haven't found quite the right combination.
    Thanks. Any help is greatly appreciated.

  • Easy way to write out internal table to database table ?

    hi friends,
    i have a special requirement:
    as i do not want to change the profile settings on an r/3 4.6c machine, i want to modify my program so it can handle even large amount of data. the plan is to fill internal table and for say every 100000 rows write those out to a table on database. how could i do this most performant ?
    thanks,
    clemens

    Hi Clemens,
    This solution worked for me, which was suggested by Seshu. May be you can try this,
    Modify ZPPPRICE(your database table name) from table t_final(internal table name).
    In my case I updated Custom table.
    The internal table is of same structure as database table.
    Modify command will insert the record the record if it is new, if the record is existing then it will update the record with the internal table values.
    I got data from Excel file in to my internal table.
    Regards,
    Neelu.

  • How to make database table WRITE PROTECTED

    Dear All,
    The table TRDIR is write protected. One cannot chahge the content of that table using MODIFY or UPDATE Statemnt.
    I want this write protection in my ZABC table also.
    please suggest me how to do this..;
    Thanks in advance

    Hi,
    TRDIR is not a database table...
    its database view
    and the maintenance status for it is assigned to read only... and also the data browser setting is mentions as Display/Maintenance allowed with restriction...
    so if you want the same for your z table make a custom view for it and give the same setting no body can change the entries in the view....
    Regards,
    Siddarth

  • Help needed in reading text file to database table

    Hello experts,
    i have to insert the values from the column of this text file and insert them in my database table.
    I have done a few file to table insertions but i'm having some trouble with this one.
    Any suggestions plz
    thanks
    liab_report      1.00                                                                                                                              Page: 1
    CDC:00537 / Mon Jun-21-2010                           LIABILITY REPORT                               Mon Jun-21-2010 22:06:26
    DRAW    1; SET    1;  November 7, 2009
                         TOTAL       PAID ON         TOTAL    EXPIRED ON         TOTAL    FRAC   OUTSTANDING
                       WINNERS      06/21/10          PAID      06/21/10       EXPIRED   ROUND
      DIVISION          AMOUNT        AMOUNT        AMOUNT        AMOUNT        AMOUNT  AMOUNT        AMOUNT
        Div1              0.00          0.00          0.00          0.00          0.00    0.00          0.00
        Div2         701040.00          0.00     660146.00          0.00      40894.00    0.00          0.00
        Div3        1444128.00          0.00    1330056.00          0.00     114072.00    0.00          0.00
        Div4        4711900.00          0.00    3889700.00          0.00     822200.00    0.00          0.00
                    6857068.00          0.00    5879902.00          0.00     977166.00    0.00          0.00
    DRAW    2; SET    1;  November 14, 2009
                         TOTAL       PAID ON         TOTAL    EXPIRED ON         TOTAL    FRAC   OUTSTANDING
                       WINNERS      06/21/10          PAID      06/21/10       EXPIRED   ROUND
      DIVISION          AMOUNT        AMOUNT        AMOUNT        AMOUNT        AMOUNT  AMOUNT        AMOUNT
        Div1              0.00          0.00          0.00          0.00          0.00    0.00          0.00
        Div2         817817.00          0.00     817817.00          0.00          0.00    0.00          0.00
        Div3        1687405.00          0.00    1611742.00          0.00      75663.00    0.00          0.00
        Div4        3402100.00          0.00    3034200.00          0.00     367900.00    0.00          0.00
                    5907322.00          0.00    5463759.00          0.00     443563.00    0.00          0.00
    DRAW    3; SET    1;  November 21, 2009
                         TOTAL       PAID ON         TOTAL    EXPIRED ON         TOTAL    FRAC   OUTSTANDING
                       WINNERS      06/21/10          PAID      06/21/10       EXPIRED   ROUND
      DIVISION          AMOUNT        AMOUNT        AMOUNT        AMOUNT        AMOUNT  AMOUNT        AMOUNT
        Div1              0.00          0.00          0.00          0.00          0.00    0.00          0.00
        Div2         779933.00          0.00     769804.00          0.00      10129.00    0.00          0.00
        Div3        1605548.00          0.00    1525104.00          0.00      80444.00    0.00          0.00
        Div4        4891700.00          0.00    4256800.00          0.00     634000.00    0.00        900.00
                    7277181.00          0.00    6551708.00          0.00     724573.00    0.00        900.00

    Plz clarify whether u want to load text file as a file into database or value of this text file into database. If values are to be loaded from this text file, U can better format the text file and use SQL loader to load the file into database. By formatting the database, i mean remove the unnecessary headings and characters, kee only the values to be loaded idelimited by ' '(space) or ','(comma). Create a control file and load it into the target table.

  • Values not read from database table.

    Hi experts,
    I have an issue reading values from the database table. In my custom table I have a KUNAG field. The Sold-to partyis a 10 character field. I have saved a record with KUNAG = '0000694012'.
    But when i read the values in a program using KUNAG= '0000694012' no records are read. Kindly help
    Regards,
    Girish

    Hi,
         This field has conversion exit.
         Pass the appropriate value after converting.
    Regards,
    Srini.

  • Regarding database tables in which i can write directly

    hi experts,
                      i have to create a database table in which i can write directly in to the table with out using update statement,what sud i do for this plz help me......

    Hi Ravi,
    If you mean you need to directly update values on the screen, SE11 has a menu for the table maintenance generator. In there you can generate screens and everything needed for your table to allow entry with or without transports. You then capture the data through transaction SM30 or SM31.
    Cheers
    Wayne

  • Dynamic reading from database table

    Hi Experts,
    While reading from a database table the below statement for deletion works:
    DELETE (p_table) FROM <fs_wadbtab>.
    p_table: name of database table which is entered as a selection screen parameter
    <fs_wadbtab> : workarea of line type P_table
    However, the below statement does not work:
    READ (p_table) FROM <fs_wadbtab>.
    My requirement is to read a record from p_table with contents in a dynamic structure.
    Kindly suggest.
    Thanks.

    Just misunderstood you.
    Edited by: Karri Kemppi on Jun 23, 2010 10:00 AM

  • Fastest way to write out internal table to database table ?

    Hi friends,
    my question is, what is the fastest way to write about 1,5 mill. of rows from an internal table to a database table ?
    points will be awarded immediately,
    thanks for your help,
    clemens

    Hi Clemens,
    If you just want to write (INSERT) 1.5 million rows of an internal table into a database table, use:
    INSERT <table name> FROM TABLE <itab>.
    Transaction Log Size could be a problem, therefore writing in packages could help, but this depends on your row size, your database configuration and on the current changes to your database. May be it runs in one package, if the rows are small (few bytes) then one package will be the fastest but you'll not much faster than with reasonable packages (3-20 MBytes). On Oracle with rollback segments you will probably have no problems at 1.5 million rows.
    Best regards
    Ralph

  • Oracle DB: How to read data from a corrupted database table.

    Hi All,
    Wanted to know if there is a way I could read data from a corrupted Oracle database table?
    Are there any tools that I can use? Or does Oracle provides any mechanism to do that?
    Any pointers in this regard would be helpful.
    Thanks in Advance.

    user10600611 wrote:
    Table shows inconsistent data.You are going to have to be more specific. Inconsistent in what sense? A correct data model should not allow for inconsistencies to crop up.
    However, you may be able to use one of the many FLASHBACK features of Oracle to look at the table at a prior point in time before the corruption.
    HTH!

  • Reading infotype 2050 ( No database table )

    Hi to all experts,
    I have a requirement to display the details exactly as in infotype 2050. When you check 2050 how it is displayed the annual calender i need to display exactly as it is .I tried using LDB, Macro, FM but the database table for 2050 doesnt exist.The p2050 is there but there is no pa2050. There is no underlying database table for that infotype 2050 (annual calender display). 
    I check some related fm
    like  module      HR_PERSONAL_WORK_SCHEDULE
    any information regarding this will be greatly appreciated.
    THanks

    Actually this information is retrieved based on the data of Planned Working Time, Infotype (0007) and Absences, Attendances and Substitutions (2001, 2002, 2003), there's no specific Infotype DB Table.
    You were using the Correct FM to read the Employee's work schedule (Relevant data is retrieved in PERWS parameter)
        CALL FUNCTION 'HR_PERSONAL_WORK_SCHEDULE'               "XOQK064687
             EXPORTING                                          "XOQK064687
                  PERNR             = PSPAR-PERNR               "XOQK064687
                  BEGDA             = FIA_BEGDA                 "XOQK064687
                  ENDDA             = FIA_ENDDA                 "XOQK064687
                  SWITCH_ACTIV      = 1                         "XOQK064687
                  READ_CLUSTER      = READ_CLUSTER            "YMMAHRK037395
             TABLES                                             "XOQK064687
                  I0000             = M0000                     "XOQK064687
                  I0001             = M0001                     "XOQK064687
                  I0002             = M0002                     "XOQK064687
                  I0007             = M0007                     "XOQK064687
                  I2001             = M2001                     "XOQK064687
                  I2002             = M2002                     "XOQK064687
                  I2003             = M2003                     "XOQK064687
                  PERWS             = PSP2050                   "XOQK064687
             EXCEPTIONS                                         "XOQK064687
                  ERROR_OCCURED     = 1                         "XOQK064687
                  ABORT_OCCURED     = 2                         "XOQK064687
                  OTHERS            = 3.                        "XOQK064687
    If you need to do something similar you'll have to check the IT2050 code

  • Read the last record in the database table..

    Hi..
    I am new to ABAP. So i have one condition to read the address number field in the last record from database table by using the person number where clause field.
    But the person number is same for some the records.
    So can any tell me the logic for to read the addressnumber field in the last record of selected records from database where personnumber is equal to some thing.
    Please help me..
    Thanks
    venki

    Hi Venkat ,
    u mean to say
    person number  addressnumber
    aa1            0000000000001
    aa1            0000000000002
    aa1            0000000000003
    aa1            0000000000004
    aa2            0000000000021
    aa3            0000000000110
    if i have to read the addressnumber 00000000000004
    of the person number aa1
    u can go like
    data v_address number like addressnumber.
    sort itab by personnumber addressnumber
    loop at itab .
    at end of personnumber.
    move addressnumber to v_addressnumber ..
    endat.
    endloop.
    so using control break statements i can fetch the last record of my person number if at all the same person number is having more than one address number ..
    hope this helps,
    Regards,
    Vijay
    Message was edited by: Vijay

  • Write OBIEE report results in database table

    Hi everyone,
    I need to implement a process that executes an OBIEE report and writes the result rows to a database table.
    How can this be done?
    Thanks,
    Alex

    You can do it with delivers/scheduler and a script.
    Delviers give the content to the script and you can do what with it.
    Check this document :
    http://www.oracle.com/technology/products/bi/files/advanced%20delivery%20with%20bi%20publisher%20delivery%20manager%20api.doc

Maybe you are looking for