on 08-31-2007 7:17 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.