How to use INSERT with no column name specified?

I want to insert rows into a database table using JDBC's PreparedStatement. I want to specify all values for each row, so that in plain SQL I would not have to specify column names. I wonder if I can do same thing with JDBC in the same manner (it would save a lot of network traffic as far as I can understand)? The problem is:
I need to know the data types of the columns to use correct setXXX method on my PreparedStatement. For example: ps.setString() for CHAR data and ps.setBytes() for binary data. I can use Connection.getMetadata().getColumns(..,..,tableName,'%') to get column types for all columns in my table as a ResultSet. However but I am not sure if I get them in the right order, i.e. in the order in which the columns have been defined for the table in CREATE TABLE.
So it seems I have a tough choice: to get type information in order externally or to specify (and probably transfer via network) column names in each INSERT statement. :-(
Do I have a better choice? Any ideas will be highly appreciated..

...if I get them in the right order, ....Only reason for that is if you are using a meta-data type solution. If you are then there is no solution. After all customer name and address are both just text. How could you tell which is first even if you had a way to handle the types?
But if your inserts are fixed then try using varchars (single ticked entries.) This depends on the database/driver. If is supported then you will have to use SimpleDateFormat to format dates/times in the correct format for the database or use a prepared statement with bind variables.

Similar Messages

  • How to use a value as column name in Triggers?

    Hello All!!!!!
    How can i use a column value instead of field name in triggers? e.g. table X has one column and having following data.
    COL1*
    Id
    Name
    Contact No.
    now in triggers i want to use "Id" instead of :new.id, is it possible?
    Any solution?

    actually i am trying to write a trigger on lets say Table2 and i dont want to specify the column name in the trigger.
    CREATE OR REPLACE TRIGGER TR_AIUDR_002
    AFTER UPDATE
    ON mytable
    FOR EACH ROW
    DECLARE
    CURSOR C IS
    SELECT * FROM t_table_columns;
    BEGIN
    IF UPDATING then
    FOR I IN C LOOP
    IF *:new.column_name <> :OLD.column_name* THEN
    insert into....
    END IF;
    END LOOP;
    END IF;
    END TR_AIUDR_002;
    instead of :new.column_name <> :old.column_name i want to compare on the base of loop column
    Edited by: rha2 on Jan 31, 2009 7:04 PM

  • How to use string as a column name

    Hello,
    I have a fn getField() that returns a column delimited string - amt1,amt2 . I want to use this string as the column name in a second query on table MASTER_AMT and get the values for amt1 and amt2...so when i try....
    select getField( 'NPC_NOYTG' ) FROM MASTER_AMT
    WHERE ACTI_CODE = 'NPOR';
    the o/p i get is...
    GETFIELD('NPC_NOYTG')
    AMT1,AMT2,AMT3
    instead of...
    AMT1 AMT2
    500 0
    that i require.
    Any ideas on how to convert the string returned to a column name?
    Thanks very much
    rgds

    Try this ....
    In SQL*PLUS
    SQL> var ref_c refcursor
    --- Then type the follwing at SQL prompt
    declare
    cursor cur is
    select column_name
    from user_tab_columns a,
         (select upper(getField( 'NPC_NOYTG')) fld FROM MASTER_AMT
         WHERE ACTI_CODE = 'NPOR') col_lst
    WHERE
    instr(chr(44) || col_lst.fld || chr(44),chr(44) || a.COLUMN_NAME || chr(44) ) > 0
    AND table_name = 'MASTER_AMT';
    v_str varchar2(1000):= ' ';
    begin
    for c in cur loop
    v_str := v_str || c.column_name || ',' ;
    end loop;
    v_str := substr(v_str,1,len(v_str)-1);
    open :ref_c for
    'select ' || v_str || ' from master_amt';
    end;      
    --- after executing the above block, type the following at SQL prompt
    SQL > print ref_c
    Please let me know if this works for you. This should for any number of columns returned by the function.
    Shakti
    (http://www.impact-sol.com)
    (Developers of Guggi Oracle)

  • How can I insert an aggregated column name as a string in the target table?

    I have a large source table, with almost 70 million records.  I need to pull the sum of four of the columns into another target table, but instead of having the same four target columns I just want to have two.
    So, let's take SUM(col1), SUM(col2), SUM(col3), and SUM(col4) from the source DB & insert them into the target like this:
    SOURCE_COLUMN
    | AMOUNT
    1 col1
    | SUM_AMOUNT
    2 col2
    | SUM_AMOUNT
    3 col3
    | SUM_AMOUNT
    4 col4
    | SUM_AMOUNT
    I know how to do this in four separate Data Flows using the source, an Aggregation Transformation, a Derived Column (to hard code the SOURCE_COLUMN label), and destination... but with this many records, it takes over 3 hours to run because it has to loop
    through these records four separate times instead of once.  Isn't there a way to do this with one Data Flow?  I'm thinking maybe Conditional Split?
    Any help is appreciated, thanks!

    Hi ,
      This could be achieved using UNPIVOT transformation. The below sample uses the below source query
    SELECT 1 AS COL1,2 AS COL2,3 AS COL3,4 AS COL4
    setup the UNPIVOT transformation as below
    The output of unpivot transformation will be as below
    Hope this helps.
    Best Regards Sorna

  • How to use rowspan with display:column tag

    Folks,
    For displaying table in my project I am using display:table tag. Now in one of the column i need to use row span attribute. How can i use that.
    Waiting for the reply.

    i dont think u can set a rowspan in display:table !!!!

  • How To Create Table View With Same Column name But Different Table?

    Hi All,
    I have the problem to create a tableview with same column name but in different table.
    The Table that i have:-
    Table - PAC051MPROFORMA
    Column - mrn,visitid
    Table - PAC051TPROFORMA
    Column - mrn,visitid
    Table - PAC052MTRANSBILL
    Column - mrn,visitid
    Then i want to create a table view to view that table. This is my SQL
    CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
    As Select PAC051MPROFORMA.mrn,PAC051MPROFORMA.visitid,PAC051TPROFORMA.mrn,PAC051TPROFORMA.visitid,PAC052MTRANSBILL.mrn,PAC052MTRANSBILL.visitid
    where
    *(a.PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)*
    and
    *(a.PAC051TPROFORMA.mrn=PAC052TRANSBILL.mrn)*
    That SQL Return this error = ORA-00957: duplicate column name
    Then I modify that SQL to
    CREATE VIEW pacviewproforma (mrn,visitid)
    As Select PAC051MPROFORMA.mrn,PAC051MPROFORMA.visitid,PAC051TPROFORMA.mrn,PAC051TPROFORMA.visitid,PAC052MTRANSBILL.mrn,PAC052MTRANSBILL.visitid
    where
    *(a.PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)*
    and
    *(a.PAC051TPROFORMA.mrn=PAC052TRANSBILL.mrn)*
    This time this error return = ORA-01730: invalid number of column names specified
    What should i do?
    Thanks...

    Hi,
    SQL> CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
      2  As Select
      3  PAC051MPROFORMA.mrn,
      4  PAC051MPROFORMA.visitid,
      5  PAC051TPROFORMA.mrn,
      6  PAC051TPROFORMA.visitid,
      7  PAC052MTRANSBILL.mrn,
      8  PAC052MTRANSBILL.visitid
      9  from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
    10  where
    11  (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
    12  and
    13  (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
    CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
    ERROR at line 1:
    ORA-00957: duplicate column namePlease give different names to each column.
    Something like this..
    SQL> CREATE OR REPLACE VIEW pacviewproforma (MPROFORMA_mrn,MPROFORMA_visitid,TPROFORMA_mrn,TPROFORMA
    _visitid,MTRANSBILL_mrn,MTRANSBILL_visitid)
      2  As Select
      3  PAC051MPROFORMA.mrn,
      4  PAC051MPROFORMA.visitid,
      5  PAC051TPROFORMA.mrn,
      6  PAC051TPROFORMA.visitid,
      7  PAC052MTRANSBILL.mrn,
      8  PAC052MTRANSBILL.visitid
      9  from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
    10  where
    11  (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
    12  and
    13  (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
    View created.
    SQL> DESC  pacviewproforma;
    Name                                      Null?    Type
    MPROFORMA_MRN                                      NUMBER
    MPROFORMA_VISITID                                  NUMBER
    TPROFORMA_MRN                                      NUMBER
    TPROFORMA_VISITID                                  NUMBER
    MTRANSBILL_MRN                                     NUMBER
    MTRANSBILL_VISITID                                 NUMBER
    ORA-01730: invalid number of column names specifiedThe list of column nmae you specified during the CREATE VIEW should match with the SELECT list of the view.
    Twinkle

  • How to use variables with

    I need to get the number of lines in internal table, which would
    be easy, using DESCRIBE TABLE itab LINES lines. But the problem
    is, that I get the name of this internal table in the field of
    another internal table, so I have to use the name of internal
    table as variable, but I don't know how to use variables with
    DESCRIBE TABLE (or if this is possible).

    Hi,
    REPORT ZPRUEBA782 .
    define two tables with diferent structures.
    data: begin of table1 occurs 0,
    registro type i,
    end of table1.
    data: begin of table2 occurs 0,
    registro type i,
    repid like sy-repid,
    end of table2.
    data: rows type i.
    start-of-selection.
    fill them with data
    do 1000 times.
    table1-registro = sy-tabix.
    append table1.
    enddo.
    do 1757 times.
    table2-registro = sy-tabix.
    table2-repid = sy-repid.
    append table2.
    enddo.
    call a form that receives as input the table and returns the number
    of rows as output.
    perform howmanyrows tables table2 changing rows.
    break-point. "evaluate the number of rows
    perform howmanyrows tables table1 changing rows.
    break-point. "evaluate the number of rows
    end-of-selection.
    form howmanyrows tables itable changing rows.
    rows = 0.
    loop at itable.
    add 1 to rows.
    endloop.
    endform.
    You can try it if you don't find a better solution.
    Cheers,
    Chaitanya.

  • Selecting from a SQL Server 2005 with long column names ( 30 chars)

    Hi,
    I was able to set up a db link from Oracle 11.2.0.1 to SQL Server 2005 using DG4ODBC.
    My problem is that some column names in the Sql Server are longer than 30 chars and trying to select them gives me the ORA-00972: identifier is too long error.
    If I omit these columns the select succeeds.
    I know I can create a view in the sql server and query it instead of the original table, but I was wondering if there's a way to overcome it with sql.
    My select looks like this:
    select "good_column_name" from sometable@sqlserver_dblink -- this works
    select "good_column_name","very_long_column_name>30 chars" from sometable@sqlserver_dblink -- ORA-00972Thanks

    I tried creating a view with shorter column names but selecting from the view still returns an error.
    create view v_Boards as (select [9650_BoardId] as BoardId, [9651_BoardType] as BoardType, [9652_HardwareVendor] as
    HardwareVendor, [9653_BoardVersion] as BoardVersion, [9654_BoardName] as BoardName, [9655_BoardDescription] as BoardDescription,
    [9656_SlotNumber] as SlotNumber, [9670_SegmentId] as SegmentId, [MasterID] as MasterID, [9657_BoardHostName] as BoardHostName,
    [9658_BoardManagementUsername] as BoardManagementUsername, [9659_BoardManagementPassword] as BoardManagementPassword,
    [9660_BoardManagementVirtualAddress] as BoardManagementVirtualAddress, [9661_BoardManagementTelnetLoginPrompt] as
    MANAGEMENTTELNETLOGINPROMPT, [9662_BoardManagementTelnetPasswordPrompt] as MANAGEMENTTELNETPASSPROMPT,
    [9663_BoardManagementTelnetCommandPrompt] as MANAGEMENTTELNETCOMMANDPROMPT FROM Boards)performing a select * from this view in sqlserver works and show the short column names
    this is the error i'm getting for performing a select * from v_boards@sqlserver_dblink
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Microsoft][SQL Native Client][SQL Server]Invalid column name 'BoardManagementTelnetLoginProm'. {42S22,NativeErr = 207}[Microsoft]
    [SQL Native Client][SQL Server]Invalid column name 'BoardManagementTelnetPasswordP'. {42S22,NativeErr = 207}[Microsoft][SQL Native
    Client][SQL Server]Invalid column name 'BoardManagementTelnetCommandPr'. {42S22,NativeErr = 207}[Microsoft][SQL Native Client][SQL
    Server]Statement(s) could not be prepared. {42000,NativeErr = 8180}
    ORA-02063: preceding 2 lines from sqlserver_dblinkI also tried replacing the * with specific column names but it fails on the columns that have a long name (it doesn't recognize the short names from the view)
    what am I doing wrong?
    Edited by: Pyrocks on Dec 22, 2010 3:58 PM

  • Is it possible to create a Synonym with different column names

    Hi,
    I want to create a Synonym with different columns names (Columns not in original table) . I am not sure if this can be done . Any suggessions...
    Thanks in advance....

    Synonyms are not limited to tables. Accroding to the SQL Reference, a synonym is:
    an alternative name for a table, view, sequence, procedure, stored function, package, materialized view, Java class schema object, user-defined object type, or another synonym.
    In fact, synonyms are not even validated until they are used:
    SQL> create synonym my_synonym for table_which_does_not_exist;
    Synonym created
    SQL> select * from my_synonym;
    select * from my_synonym
    ORA-00980: synonym translation is no longer valid

  • How to use log4net with C# clients

    Hi,
    Can anybody please give an example of how to use log4net with C# clients? Foe java clients you can use the
    <logging-config>
    <destination>log4j</destination>
    How do we use it with C# clients? Any example will be appreciated.
    Thanks.
    -ali

    Ali,
    The following is an example on how to define a custom logger (including log4net) in tangosol-coherence-override.xml for coherence .NET client; you need Coherence .NET client 3.7.1 patch 1.
    <coherence xmlns="http://schemas.tangosol.com/coherence">
    <logging-config>
    <destination>common-logger</destination>
    <logger-name>log4net</logger-name>
    <severity-level>9</severity-level>
    <message-format>(thread={thread}): {text}</message-format>
    <character-limit>8192</character-limit>
    </logging-config>
    </coherence>
    You also need to configure log4net in app.config. Please see the following web page for more information:
    http://netcommon.sourceforge.net/docs/2.0.0/reference/html/ch01.html
    -Luk

  • How to use stylus with ipad2

    Just bought a stylus for taking notes but do not know how to use it with the ipad2? Some special apps required?
    Thanks!

    Take a look at Memo, Penultimate, and Draw Pad to name a few. Several in the app store.But you do need an app that will accept input using a stylus or your finger rather than the keyboard. Several art/drawing programs are available as well.

  • How to use the default database service name on creating procedure for data

    how to use the default database service name on creating procedure for datagaurd client failover ??? all oracle doc says create a new service as below and enable at DB startup. but our client is using/wanted database default service to connect from application on the datagaurd environment (rac to non rac setup).please help.
    Db name is = prod.
    exec DBMS_SERVICE.CREATE_SERVICE (service_name => 'prod',network_name =>'prod',failover_method => 'BASIC',failover_type => 'SELECT',failover_retries => 180,failover_delay => 1);
    says already the service available.
    CREATE OR REPLACE TRIGGER manage_dgservice after startup on database DECLARE role
    VARCHAR(30);BEGIN SELECT DATABASE_ROLE INTO role FROM V$DATABASE;
    IF role = 'NO' THEN DBMS_SERVICE.START_SERVICE('prod');
    END IF;
    END;
    says trigger created, but during a swithover still the service is listeneing on listener.
    tns entry.
    prod =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (LOAD_BALANCE = YES)
    (ADDRESS = (PROTOCOL = TCP)(HOST = prod1)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = prod2)(PORT = 1521)) ---> primary db entry
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = proddr)(PORT = 1521)) --> DR DB entry
    (CONNECT_DATA =
    (SERVICE_NAME = prod)
    thanks in advance.
    Edited by: 854393 on Dec 29, 2012 11:52 AM

    Hello;
    So in the example below replace "ernie" with the alias you want the client to use.
    I can show you how I do it :
    First an entry need to be added to the client tnsnames.ora that uses a SERVICE_NAME instead of a SID.
    ernie =
    (DESCRIPTION =
        (ADDRESS_LIST =
           (ADDRESS = (PROTOCOL = TCP)(HOST = Primary.host)(PORT = 1521))
           (ADDRESS = (PROTOCOL = TCP)(HOST = Standby.host)(PORT = 1521))
           (CONNECT_DATA =
           (SERVICE_NAME = ernie)
    )Next the service 'ernie' needs to be created manually on the primary database.
    BEGIN
       DBMS_SERVICE.CREATE_SERVICE('ernie','ernie');
    END;
    /After creating the service needs to be manually started.
    BEGIN
       DBMS_SERVICE.START_SERVICE('ernie');
    END;
    /Several of the default parameters can now be set for 'ernie'.
    BEGIN
       DBMS_SERVICE.MODIFY_SERVICE
       ('ernie',
       FAILOVER_METHOD => 'BASIC',
       FAILOVER_TYPE => 'SELECT',
       FAILOVER_RETRIES => 200,
       FAILOVER_DELAY => 1);
    END;
    /Finally a database STARTUP trigger should be created to ensures that this service is only offered if the database is primary.
    CREATE TRIGGER CHECK_ERNIE_START AFTER STARTUP ON DATABASE
    DECLARE
    V_ROLE VARCHAR(30);
    BEGIN
    SELECT DATABASE_ROLE INTO V_ROLE FROM V$DATABASE;
    IF V_ROLE = 'PRIMARY' THEN
    DBMS_SERVICE.START_SERVICE('ernie');
    ELSE
    DBMS_SERVICE.STOP_SERVICE('ernie');
    END IF;
    END;
    /lsnrctl status - should show the new service.
    When I do this the Database will still register with the listener. I don't give that to the clients. That one will still be available but nobody knows about it. Meanwhile "ernie" moves with the database role.
    So in my example the default just hangs out in the background.
    Best Regards
    mseberg
    Edited by: mseberg on Dec 29, 2012 3:51 PM

  • How to view all tables and column names from a remote database

    Hey Guys,
    I have a database in a remote server. I have the db link and the schema name.. Now i want to view all the tables in the remote database with column names.. I dont have access to that database using sql developer.. But i can view some tables using the db link..Is there any way i can view all the tables with the column names?

    user10683742 wrote:
    Dont think i have DBA access..It gives the following error
    ORA-00942: table or view does not exist
    00942. 00000 - "table or view does not exist"You don't have to have 'dba' access, per se. You just have to have SELECT ALL TABLES privilege. when you use a db_link, you are connecting to the remote db with the user defined in the link, and .. on that db .. you will have the privileges of the user defined in the db link. Exactly as if you had used sqlplus to connect to that db with that user.

  • Screens, like them? hate them? also, how to use actionscript with them.

    So I haven't used a flash version since Flash 8. I've now been given CS4 and inheritid a flash document that uses screens. After 2 weeks of figuring out how the presentation is made to 'go' from slide to slide on keydown, I finally discovered today that it is the default behaviour.
    Ok, so this leads me to my next question. How do people here feel about screens? Like them? Hate them? I feel like I could do half of this stuff easier with actionscript. I feel constrained by this. Not to mention I put some animation into a movie clip and it seems like it's not playing, like it's just poping right to the stop action at the end of that clip.
    Can anyone tell me how to use actionscript with screens? I looked at help, but of course, the help file doesn't give me what I really need to know. I'd like to put my actions on frame one of the root and let that control everything else. But what is the syntax like? The help file recommends external scripts, but that is not an option as the CEO takes this presentation with him and I can't risk having him lose the code.
    Please give me any advice you may have. Thank you!
    Stan

    Not that I'm any kind of expert on this matter, but I've never heard of screens, at least not by that name, and I have been fiddling with Flash for about 9 years now (like this case, I still learn new things all the time... though I'm still clueless as to what they are... chances are I won't miss 'em).
    When you mentioned scenes though, my personal recommendation is along the party lines of avoid them like the plague... use one timeline and/or movieclips for everything.  I have never used them in my own work, and my bias is partly due to having inherited them in other people's work... they make it hard to find things, especially when you have to first discover they're being used to begin with.  From a technical stance, I have found them to be problematic to manage as far as navigation goes.

  • How to use INSERT query ?

    Frenz,
    I have created one internal table and i am doing loop on it like...
    Loop at it_data into wa_data.
    Endloop.
    I want to insert some data into table zdata.
    How to use INSERT records on this data base table?
    Give me one example.
    Regards,
    RH

    Hi,
    explain better what you want....
    Do you want to change data in an existing raw?
    Loop at tb_data into wa_data.
    wa_data-field1 = 'jsahdu'.
    modify tb_data from wa_data.
    endloop.
    If you want to add raws you use APPEND statement.
    In the end you'll modify your table zdata from the internal table tb_data:
    MODIFY zdata FROM TABLE tb_data.
    Using modify you change raws basing on primary keys. If a raw doesn't exist it will be inserted.
    Regards

Maybe you are looking for

  • Partner profile in case of Idoc to File scenario

    Hi I have ECC system and PI system. Scenario as : ECC will send the Idoc to PI ..PI system will Convert this to flat file and provide it to Legarcy system I made Partner profile in sending system (ECC) and maintained Message type 'MATMAS' as Outbound

  • From Where i Can get the List of Authorised Manufa...

    Do you know anyone who can give us some informations about the authorised manufacturers in China who make geniune Nokia Mobiles not the fake ones.Please share your experiances with us as we are thinking to import some Nokia Handsets from China to Uni

  • How much does a macbook display repair cost

    My white macbook's display is pretty much shattered. I bought it in 2006 so i dont have warranty or apple care. I would like to know how much it will cost to fix it.I remember once an apple technician told me that there is a $300 package that will re

  • Concerned about losing 7 Express files when installing Logic 8

    Will my Logic Express 7 files be deleted or corrupted when I install Logic 8? From, "Before You Install Logic Studio": WARNING: If you have installed Logic Express or Logic Pro 7 on your computer, the Logic Studio installer will delete some of the fi

  • No such file or directory

    Hi all Having opened my iBook g4, it immediately goes to a black page showing the following: /etc/master.passwrd: No such password or directory. Any idea what I need to do to get the laptop back up and running normally??