Skip to Content
avatar image
Former Member

Inserting and Updating records in ORACLE using WebDynpro Java

Hi All

I got connected to oracle backend (using my previous thread), but now i want to insert and update the records

i have created views for insert and update,

Thanks in advance

Sushma

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 31, 2007 at 06:19 AM

    Hi Sushma,

    You can insert and update records into oracle Database using a <i>PREPARED STATEMENT</i>

    <u><b>Insert</b></u>

    PreparedStatement prestate=con.prepareStatement("INSERT INTO <table_name> values(?,?,?)");
    prestate.setInt(1,SomeInt);
    prestate.setString(2,SomeString);
    prestate.setDate(3,SomeDate);
    ps.executeUpdate();
    
    <u><b>Update</b></u>
    PreparedStatement ps1=null;
    ps1=conn1.prepareStatement("update <tablename> set Var1=?,var2=?,var3=?,var4=?,var5=? );//update statement
    ps1.setString(1,aa);
    ps1.setDate(2,bb);
    ps1.setDate(3,cc);
    ps1.setString(4,dd);
    ps1.setString(5,ee);
    
    ps1.executeUpdate();

    i didnt mentioned regarding connection in this code.. you need to create a connection and close the connection once you finish your session

    Regards

    Chaitanya.A

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Chaitanya

      I can able to insert and update now. i eve tried delete usind the same .that is also working

      Thank you

      Sushma

  • avatar image
    Former Member
    Aug 31, 2007 at 06:41 AM

    Hi shusma..

    chk this link..

    <b><u>Creating Connection</u></b>

    package com.sap.xirig;

    import javax.naming.*;

    import javax.sql.*;

    import java.sql.*;

    public class DBLookup {

    String Conn_Status = "Not Connected";

    String Language_Desc = "Empty";

    String Language_Cd = "Empty";

    Connection conn;

    Context ctx;

    DataSource ds;

    //Constructor for the DBLookup object

    public DBLookup {

    try {

    ctx = new InitialContext();

    if (ctx == null) {

    throw new Exception("Boom - No Context");

    }

    // If JDBC 2.0 connection is used please create the DataSource object as below

    // ds = (DataSource) ctx.lookup("jdbc/ORACLEDATASOURCE");

    // If JDBC 1.0 connection is used please create the DataSource object as below

    // ds = (DataSource) ctx.lookup("jdbc/notx/ORACLEDATASOURCE");

    if (ds == null) {

    throw new Exception("Boom - No dataSource");

    }

    }

    catch (Exception e) {

    e.printStackTrace();

    }

    }

    public String getLanguageDesc(String v_str) {

    Statement stmt = null;

    ResultSet rst = null;

    try {

    if (ds != null) {

    conn = ds.getConnection();

    Conn_Status = "Could not get connection to

    datasource";

    if (conn != null) {

    Conn_Status = "Got Connection " +

    conn.toString();

    stmt = conn.createStatement();

    rst = stmt.executeQuery("SELECT

    LANGUAGE_DESC FROM LANGUAGETRANSLATION WHERE LANGUAGE_CD='" + v_str +

    "'");

    if (rst.next()) {

    Language_Desc = rst.getString(1);

    }

    conn.close();

    }

    }

    }

    catch (Exception e) {

    e.printStackTrace();

    }

    finally {

    if (rst != null) {

    try {

    rst.close();

    }

    catch (Exception e) {

    e.printStackTrace();

    }

    }

    if (stmt != null) {

    try {

    stmt.close();

    }

    catch (Exception e) {

    e.printStackTrace();

    }

    }

    if (conn != null) {

    try {

    conn.close();

    }

    catch (Exception e) {

    e.printStackTrace();

    }

    }

    }

    return Language_Desc;

    }

    }

    http://e-docs.bea.com/wls/docs81/oracle/API_joci.html

    Hope this will help u..

    URs GS

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 28, 2007 at 02:33 PM

    Hi Sushma,

    I am trying to insert some question papers in to oracle , but i am not able to even retrive the data .

    Thanks,

    Sumanth Reddy

    Add comment
    10|10000 characters needed characters exceeded