on 08-29-2007 12:04 PM
hi experts,
how to insert record dynamic in oracle db thro user input in webdynpro view
name:........
save
thank you in advance
---
vijai
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.