cancel
Showing results for 
Search instead for 
Did you mean: 

insert record dynamic in oracle db thro user input

Former Member
0 Kudos

hi experts,

how to insert record dynamic in oracle db thro user input in webdynpro view

name:........

save

thank you in advance

---

vijai

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi

1) if APPLICANTID,APPFIRSTNAME,APPMIDDLENAME only these are your table columns try with the following code. give SOP with all lines and check.

2) alse check whether you have any other not null column in your table.

3) Even then if it does not work remove schema name try with giving only table name in your prepared statement.

4) if your DB is in remote system try to ping it once.

Connection con = null;

Statement stmt = null;

DataSource ds=null;

ResultSet rs=null;

try

{

String APPID = wdContext.currentStudentinfoElement().getAPPID();

String APPFNAME = wdContext.currentStudentinfoElemen().getStudentfirstname();

String APPMNAME = wdContext.currentStudentinfoElement().getStudentmiddle();

InitialContext x = new InitialContext();

ds = (DataSource)x.lookup("jdbc/XD1_Oracle_Pool");

con = ds.getConnection();

PreparedStatement ps=con.prepareStatement("INSERT INTO SAPSR3DB.APPLICANTDTLS(APPLICANTID,APPFIRSTNAME,APPMIDDLENAME) VALUES (?,?,?)");

ps.setString(1,APPID);

ps.setString(2,APPFNAME);

ps.setString(3,APPMNAME);

ps.executeUpdate();

}

catch(Exception e)

{

wdComponentAPI.getMessageManager().reportException("Connection failed",true);

}finally{

try{

if(con!=null)

con.close();

}catch(Exception ex){

}

}

Regards

Abhijith YS

Former Member
0 Kudos

hi experts,

here is my code i am trying

Connection con = null;

Statement stmt = null;

DataSource ds=null;

ResultSet rs=null;

try

{

String APPLICANTID = wdContext.currentStudentinfoElement().getAPPID();

String APPFIRSTNAME = wdContext.currentStudentinfoElement().getStudentfirstname();

String APPMIDDLENAME = wdContext.currentStudentinfoElement().getStudentmiddle();

InitialContext x = new InitialContext();

ds = (DataSource)x.lookup("jdbc/XD1_Oracle_Pool");

con = ds.getConnection();

PreparedStatement ps=con.prepareStatement("INSERT INTO SAPSR3DB.APPLICANTDTLS(APPLICANTID,APPFIRSTNAME,APPMIDDLENAME) VALUES (?,?,?)");

ps.setString(1,APPLICANTID);

ps.setString(2,APPFIRSTNAME);

ps.setString(3,APPMIDDLENAME);

ps.executeUpdate();

}

catch(Exception e)

{

wdComponentAPI.getMessageManager().reportException("Connection failed",true);

}

thank you,

-


vijai

Former Member
0 Kudos

Hi! Vijay,

The code you have written should work fine.

Are you getting any Error?If yes then paste that error.

Thanks,

Mithileshwar

Former Member
0 Kudos

Hi Vijay

i used the same code it worked fine.. this is one of the way to insert records into oracle DB.

1)first get the values into a variable using

String APPLICANTID = wdContext.currentStudentinfoElement().getAPPID();

..

..

2)use prepared statement and use insert statement to insert the data into the database

3) use executeupdate

4)* don forget to close the opened connection

Regards

Chaitanya.A