SQLJ classes (Will not insert result into table)

/*@lineinfo:filename=SqljCircle*//*@lineinfo:user-code*//*@lineinfo:1^1*/import java.sql.SQLException ;
import oracle.sqlj.runtime.Oracle;
// iterator for the select
/*@lineinfo:generated-code*//*@lineinfo:5^1*/
// SQLJ iterator declaration:
class myIter
extends sqlj.runtime.ref.ResultSetIterImpl
implements sqlj.runtime.NamedIterator
public myIter(sqlj.runtime.profile.RTResultSet resultSet)
throws java.sql.SQLException
super(resultSet);
RadiusNdx = findColumn("Radius");
public int Radius()
throws java.sql.SQLException
return resultSet.getIntNoNull(RadiusNdx);
private int RadiusNdx;
/*@lineinfo:user-code*//*@lineinfo:5^33*/
class SqljCircle
//Main method
public static void main (String args[])
try {
// set the default connection to the URL, user, and password
// specified in your connect.properties file
Oracle.connect(SqljCircle.class, "connect.properties");
SqljCircle ti = new SqljCircle();
ti.runExample();
} catch (SQLException e) {
System.err.println("Error running the example: " + e);
} //End of method main
//Method that runs the example
void runExample() throws SQLException
myIter iter;
/*@lineinfo:generated-code*//*@lineinfo:28^1*/
// #sql iter = { select radius from RADIUS_VALS };
sqlj.runtime.ConnectionContext __sJT_connCtx = sqlj.runtime.ref.DefaultContext.getDefaultContext();
if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX();
sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
synchronized (__sJT_execCtx) {
sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, SqljCircle_SJProfileKeys.getKey(0), 0);
try
sqlj.runtime.profile.RTResultSet __sJT_result = __sJT_execCtx.executeQuery();
iter = new myIter(__sJT_result);
finally
__sJT_execCtx.releaseStatement();
/*@lineinfo:user-code*//*@lineinfo:28^45*/
while (iter.next()) {
// To see the radius values:
System.out.println(iter.Radius());
int radInput = iter.Radius();
double result=area(radInput);
// To see the result values:
System.out.println(result);
/*@lineinfo:generated-code*//*@lineinfo:38^1*/
//#sql { insert into RADIUS_VALS values(:radInput,:result) };
sqlj.runtime.ConnectionContext __sJT_connCtx = sqlj.runtime.ref.DefaultContext.getDefaultContext();
if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX();
sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
int __sJT_1 = radInput;
double __sJT_2 = result;
synchronized (__sJT_execCtx) {
sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, SqljCircle_SJProfileKeys.getKey(0), 1);
try
__sJT_stmt.setInt(1, __sJT_1);
__sJT_stmt.setDouble(2, __sJT_2);
__sJT_execCtx.executeUpdate();
finally
__sJT_execCtx.releaseStatement();
/*@lineinfo:user-code*//*@lineinfo:38^51*/
/*@lineinfo:generated-code*//*@lineinfo:39^1*/
//#sql { commit };
sqlj.runtime.ConnectionContext __sJT_connCtx = sqlj.runtime.ref.DefaultContext.getDefaultContext();
if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX();
sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
synchronized (__sJT_execCtx) {
sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, SqljCircle_SJProfileKeys.getKey(0), 2);
try
__sJT_execCtx.executeUpdate();
finally
__sJT_execCtx.releaseStatement();
/*@lineinfo:user-code*//*@lineinfo:39^13*/
iter.close();
// Utility function to calculate the area
public static double area (int rad) {
double pi=3.1415926;
double areacircle=pi*rad*rad;
return areacircle;
}/*@lineinfo:generated-code*/class SqljCircle_SJProfileKeys
private static SqljCircle_SJProfileKeys inst = null;
public static java.lang.Object getKey(int keyNum)
throws java.sql.SQLException
if (inst == null)
inst = new SqljCircle_SJProfileKeys();
return inst.keys[keyNum];
private final sqlj.runtime.profile.Loader loader = sqlj.runtime.RuntimeContext.getRuntime().getLoaderForClassT(getClass());
private java.lang.Object[] keys;
private SqljCircle_SJProfileKeys()
throws java.sql.SQLException
keys = new java.lang.Object[1];
keys[0] = sqlj.runtime.ref.DefaultContext.getProfileKey(loader, "SqljCircle_SJProfile0");
This SQLJ class compiles and runs ok, it retrieves a number from a table in my database, computes the result and prints them both out but it will not insert the result back into a table in my database, WHY????
Philip.

Thanks a million to all of you, the final working code;
Zed
<%
          String name = request.getParameter("name");
          String connectionURL = "jdbc:mysql://localhost:3306/";
          String dbName = "test";
          String userName = "root";
          String password = "";
     Connection connection = null;
     PreparedStatement pstatement = null;
     Class.forName("com.mysql.jdbc.Driver").newInstance();
try {
     connection = DriverManager.getConnection(connectionURL+dbName,userName,password);
     String queryString = "INSERT INTO employees(id, name) VALUES (id, " + "'" + name + "'" + ")";
     pstatement = connection.prepareStatement(queryString);
     pstatement.executeUpdate(queryString);
     catch (Exception ex) {
     out.println("Error = " + ex.toString());
     pstatement.close();
     connection.close();
%>

Similar Messages

  • How to insert the select query result into table?

    How to insert the select query result into table?
    SELECT  top 20 creation_time  
            ,last_execution_time 
            ,total_physical_reads
            ,total_logical_reads  
            ,total_logical_writes
            , execution_count 
            , total_worker_time
            , total_elapsed_time 
            , total_elapsed_time / execution_count avg_elapsed_time
            ,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
             ((CASE statement_end_offset 
              WHEN -1 THEN DATALENGTH(st.text)
              ELSE qs.statement_end_offset END 
                - qs.statement_start_offset)/2) + 1) AS statement_text
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
    ORDER BY total_elapsed_time / execution_count DESC;
    Thanks,
    Tirumala

    1. SELECT INTO
    Below method will create table when data is inserted from one table to another table. Its useful when you need exactly same datatype as source table.
    Use AdventureWorks2008R2;
    Go
    ---Insert data using SELECT INTO
    SELECT AddressLine1, City
    INTO BothellAddresses
    FROM Person.Address
    where City = 'Bothell';
    GO
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    2. INSERT INTO SELECT
    Below method will need table to be created prior to inserting data. Its really useful when table is already created and you want insert data from
    another table.
    Use AdventureWorks2008R2;
    Go
    ---Create Table
    CREATE TABLE BothellAddresses (AddressLine1 NVARCHAR(60), City NVARCHAR(30))
    ---Insert into above table using SELECT
    INSERT INTO BothellAddresses(AddressLine1, City)
    SELECT AddressLine1, City
    FROM Person.Address
    where City = 'Bothell';
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

  • Files moving to NFS error folder - Could not insert message into duplicate check table

    Hi Friends
    Have anyone faced this error, could suggest me why.
    The CSV Files failed on Sender Channel and moves to NFS error path  and in the log it says as below.
    Error: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Could not insert message  into duplicate check table. Reason: com.ibm.db2.jcc.am.SqlTransactionRollbackException: DB2 SQL Error

    Hi Uma - is that a duplicate file? have you enabled duplicate file check in sender channel?
    please check if the below note is applicable
    1979353 - Recurring TxRollbackException with MODE_STORE_ON_ERROR stage configuration

  • I purchased the Logitech F310 game controller for my 2011 MacBook Pro. How do I get the driver installed for it. The Disk that came with the controller is a mini disk and will not insert into my laptop.

    I purchased the Logitech F310 game controller for my 2011 MacBook Pro. How do I get the driver installed for it. The Disk that came with the controller is a mini disk and will not insert into my laptop.

    May not make a difference anyway. The Logitech support site does not show drivers for Mac OS for the F310:
    http://www.logitech.com/en-us/support/gamepad-f310?crid=411
    I'd contact their support to find out if there is a Mac driver available, and if they can either give you a web link to get it, e-mail you the software, or snail-mail you a standard-size disk with the drivers.

  • Insert data into table 1 but remove the duplicate data

    hello friends,
    i m trying to insert data into table tab0 using hints,
    query is like this..
    INSERT INTO /*+ APPEND PARALLEL(tab0) */ tab NOLOGGING
    (select /*+ parallel(tab1)*/
    colu1,col2
    from tab1 a
    where a.rowid =(select max (b.rowid) from tab2 b))
    but this query takes too much time around 5 hrs...
    bz data almost 40-50 lacs.
    i m using
    a.rowid =(select max (b.rowid) from tab2 b))....
    this is for remove the duplicate data..
    but it takes too much time..
    so please can u suggest me any ohter option to remove the duplicate data so it
    resolved the optimization problem.
    thanks in advance.

    In the code you posted, you're inserting two columns into the destination table. Are you saying that you are allowed to have duplicates in those two columns but you need to filter out duplicates based on additional columns that are not being inserted?
    If you've traced the session, please post your tkprof results.
    What does "table makes bulky" mean? You understand that the APPEND hint is forcing the insert to happen above the high water mark of the table, right? And you understand that this prevents the insert from reusing space that has been freed up because of deleted in the table? And that this can substantially increase the cost of full scans on the table. Did you benchmark the INSERT without the APPEND hint?
    Justin

  • Can not insert null into foreign key issue

    Hi ,
    I am having parent-child relationship table.
    In the child table when I am adding a new record , data is getting inserted with foreign key.
    After insert if I immediately update the same record. Its giving error that can not insert null into foreign key.
    If i click on rollback button I am able to update that record properly.

    Hi ,
    I am having parent-child relationship table.
    In the child table when I am adding a new record , data is getting inserted with foreign key.
    After insert if I immediately update the same record. Its giving error that can not insert null into foreign key.
    If i click on rollback button I am able to update that record properly.

  • Can not insert or update [TABLE] from internal table in method

    I've faced a problem with OO abap. I've tried to insert into [ TABLE ] from internal table, but i've got error msg after i compiled.
    "An explicit work area is necessary in the OO context. Use "INSERT wa INTO [TABLE] itab""
    After  i changed to loop in work area and INSERT INTO  [TABLE] VALUES gw_data., everything is fine, can compile and run.
    This is error code.
      METHOD set_data_to_table.
        REFRESH gi_data.
        CLEAR gi_data.
        IF gi_file[] IS NOT INITIAL.
    * Set data for modify table
          LOOP AT gi_file INTO gw_file.
            MOVE-CORRESPONDING gw_file TO gw_data.
            me->conversion_input( EXPORTING im_vendor = gw_data-vendor
                                  CHANGING  ch_vendor = gw_data-vendor ).
            APPEND gw_data TO gi_data.
          ENDLOOP.
          INSERT [TABLE] FROM TABLE gi_data.
    *      LOOP AT gi_data INTO gw_data.
    *        INSERT INTO  [TABLE] VALUES gw_data.
    *        IF sy-subrc = 0.
    *          COMMIT WORK.
    *        ELSE.
    *          ROLLBACK WORK.
    *        ENDIF.
    *      ENDLOOP.
        ELSE.
          MESSAGE 'No data found' TYPE 'I'.
        ENDIF.
      ENDMETHOD.                    "set_data_to_table

    Hi Matthew,
    I think there is no difference in database insert between OO and non-OO.
    The correct syntax according to ECC600 online documentation is
    [Inserting Several Lines|http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/content.htm]
    To insert several lines into a database table, use the following:
    INSERT target FROM TABLE itab \[ACCEPTING DUPLICATE KEYS].
    This writes all lines of the internal table itabto the database table in one single operation. If one or more lines cannot be inserted because the database already contains a line with the same primary key, a runtime error occurs. You can prevent the runtime error occurring by using the addition ACCEPTING DUPLICATE KEYS.
    Whenever you want to insert more than one line into a database table, it is more efficient to work with an internal table than to insert the lines one by one.
    I think the syntax
    INSERT my_dbtable FROM TABLE gi_data.
    should work, your suggestion may lead to syntax error.
    Regards,
    Clemens

  • Insert data into table from JSP page using Entity Beans(EJB 3.0)

    I want to insert data into a database table from JSP page using Entity Beans(EJB 3.0).
    1. I have a table 'FRIENDS', (in Oracle 10g database).
    2. It has two columns, 'NAME' and 'CITY'. Both have datatype strings(varchar2).
    3. Now from a JSP page, having two textfields, 'NAME' and 'CITY', I want to insert data into table 'FRIENDS'.
    4. In between JSP and database is a Entity Bean(EJB 3.0) and a stateless session bean.
    5. I am using JDev as editor.
    Please provide me code ASAP or link with similar example.
    Thank you.
    Anurag

    Hi,
    I am also trying that scenario. So u can
    Post the jsp form data to a Servlet which will act as a Controller.
    In the servlet invoke the business method.
    Similar kind of app is in www.roseindia.net
    Hope this would help u.
    Meanwhile if u get any optimal solution, pls post it.
    Thanks,
    Happy Java Coding.

  • Inserting image into table

    hi,
    i m create table, then create procedure, procedure is successfully compile, but when i m trying to insert image into table it error out.
    for inserting image i go with
    EXECUTE insert_image_file(1,'C:\sunset.jpg');
    sunset.jpg is image which i want to insert in table, and which is present on 'c drive'.
    when execute the following error are shown
    ORA-22285: non-existent directory or file for FILEOPEN operation
    ORA-06512: at "SYS.DBMS_LOB", line 635
    ORA-06512: at "SCOTT.INSERT_IMAGE_FILE", line 26
    ORA-06512: at line 1
    how to solve it.
    regards
    prashant

    Prashant wrote:
    CREATE OR REPLACE PROCEDURE insert_image_file (p_id NUMBER, p_image_name IN VARCHAR2)
    ...snipped...Not very nice code... why create an empty image row, then lock it (it is already locked by the uncommitted insert statement), and then update it again? Not very efficient or sensible.
    image is on local machine.When a row is created on the server from user input on some PC, who supplied that input? Who read the user's keyboard input on that PC to obtain the values for the columns for the row to create?
    Did PL/SQL read the keyboard of that remote PC? Of course not. The client program on that PC read the keyboard input. It then made a client call to the Oracle server. It supplied the data entered via the keyboard by the user to the Oracle server (using a PL/SQL call or using a SQL statement call to Oracle).
    Now why would a local image data on that PC be treated any differently than the keyboard data on that PC? How can you expect PL/SQL code running on the Oracle server, to read that image data from the remote PC when the same PL/SQL code is incapable of reading keyboard input from that very same PC?
    You need to review your understanding of client-server and how it pertains to using Oracle within client-server architecture.

  • Large insert op into table with indexes

    Hi,
    Oracle 8.1.7.0. Empty table (after truncate) with two indexes. Need to insert about 40 billions records. What is better way to complete this task:
    1. Drop indexes, insert data then build indexes.
    2. Simply insert data into table.
    Thanks.

    The only way to find out is to test... For example, I did a test on my single-cpu box with Oracle 9i. My test was to load all the rows from DBA_SOURCE (only 650k rows). I found that a single insert statement with bitmap indexes online ran faster than the total elapsed time for taking the indexes offline, inserting, and bringing the indexes back up...
    With 40-billion rows, I presume you're using partitioned tables and enabling parrallel DML. Thus, your test will be much different than mine...
    In past ETL projects I worked on, I found little difference in timing. I decided that I didn't want to drop indexes (it was ver8i) so I loaded the empty tables with indexes (and constraints) enabled...
    Stan

  • How to insert data into table control

    hi experts,,
           i have inserted data into data base table through table control .
    now i want to insert data into table control through database table.
      how to delete data from table control for selected row

    Hi
    go through this link.
    http://www.****************/Tutorials/ABAP/TableControl/Demo.htm

  • Please recommend if we have options to read xml file and insert data into table without a temporary table.

    Please recommend if we have options to read xml file and insert data into table without a temporary table. 

    DECLARE @data XML;
    SET @data =N'<Root>
    <List RecordID="946236" />
    <List RecordID="946237" />
    <List RecordID="946238" />
    <List RecordID="946239" />
    <List RecordID="946240" />
    </Root>'
    INSERT INTO t (id) SELECT T.customer.value('@RecordID', 'INT') AS id
    FROM @data.nodes('Root/List')
     AS T(customer);
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Re.... Elements 12... organizer will not upload media into the organizer...media is on hard drive

    how do I get classromm in a book media into the organizer?? All Lessons are on the hard drive but
    will not import media into organizer!! HELP

    What type of file are they?
    Can you see the folder in the left hand panel?
    If you can't see the folder list click on the two pins to expand the tree. Then right-click to add the contents.

  • Nikon Df RAW (NEF) files will not load previews into Lightroom 5.4. Nikon d300s RAW (NEF) files load just fine. Df files do not.

    Nikon Df RAW (NEF) files will not load previews into Lightroom 5.4. Nikon d300s RAW (NEF) files load just fine. Df files do not.

    Thank you for your response.
    I have loaded directly into Lightroom using import and via Nikon Capture NX2. RAW files display fine in Capture.
    In Lightroom, blank previews are created for each available image, with the message "Preview unavailable for this file."

  • Widget will not insert

    Working with Dreamweaver and Flash software.  Using a template, couldn't get flv videos to insert correctly, got a white blank box at the tested website.  Finally downloaded widget as a solution, now widget will not insert.  It appears on the insert menu, I put the cursor in the insertion point and click on widget, and nothing happens.  I don't get the pop up widget box, I get nothing.  At my wits end.  Please help.  Working on thesis project and deadline coming up soon.

    After I posted, I noticed a similar post below.  Couldn't reinstall Dreamweaver as I have a thesis project I've been working on for awhile stored there.  Saw the fix to go to preferences and general and the problem was on the unchecked box to show dialog upon insertion.  Once I checked that box, the widget pop up worked.  Can't believe I have spent hours of wasted valuable time trying to figure this out.  Thanks!

Maybe you are looking for

  • How do I get rid of the Facebook blue box on my Firefox pages???

    How do I get rid of - and why is - the little blue box with Facebook asking me to go through Facebook instead of directly to where I want to go??? I do not wish to allow Facebook into my life any more than it is now. Thank you

  • How can I change the Apple ID on iMessage?

    I bought this iPhone 4 from my aunt, and it is currently sim-locked to Japan. My problem is that I can't change the Apple ID on iMessage, and my aunt's Apple ID keeps asking for the password. There are no other options in the iMessage than iMessage o

  • StorageDir in Application.xml

    We store all of our flv files on a network storage device. I've setup a VirtualDirectory in vhosts.xml that maps a virtual path to the network drive. I have noted the StorageDir in application.xml and tried changing this to the network drive. It was

  • Can't eject a phantom remote disc?

    I have discovered, in Finder, a phantom remote disc.  It was a link to an Ibook with a name.  Since I have been researching it, the name has disappeared.  I have attempted to eject it.  How do I get rid of it and what damage has it likely done?

  • My iPad goes black before asking me to renew the lease.  Why?

    My ipad2 keeps asking me to renew the lease. Why?