This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Struts and the fly likes Insertion Values not get stored in sql server using stored procdure in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Insertion Values not get stored in sql server using stored procdure in struts2" Watch "Insertion Values not get stored in sql server using stored procdure in struts2" New topic
Author

Insertion Values not get stored in sql server using stored procdure in struts2

bugsnow nowbugs
Greenhorn

Joined: Jun 07, 2010
Posts: 1
Help me,

AM using struts2 frame work, am sending the values to db method and i have written code, my try block executed no err msg in console, I get the msg Stored procedure exe succ, but my values are not get insert into table. In sql stored procedure 4 input params and 4 output param has been given. I get values in debug mode for the values for input params, which i get that form bean, but not for output params, here with i add my code please help me with this bug.

package db;

import java.util.List;
import java.sql.*;


import hbsbean.AddNewFieldsBean;

public class ApplicationStoredDB {
public List<AddNewFieldsBean> storeNewRecords(AddNewFieldsBean bean)
{
List<AddNewFieldsBean> nbean=null;
Connection conn=null;
String jdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String dbURL = "jdbc: odbc:sqlserver";
String usernameDbConn = "root";
String passwordDbConn = "hbsroot";
try
{
Class.forName(jdbcDriver).newInstance();
conn = DriverManager.getConnection(dbURL,usernameDbConn,passwordDbConn);
}
catch (Exception e)
{
System.out.println("jdbc driver not found:" + dbURL);
e.printStackTrace();
}

try
{
//make a callable statement for a stored procedure.

CallableStatement cstmt = conn.prepareCall("{call proc_application_menu(?, ?, ?, ?, ?, ?, ? ,?)}");


//set the values of the stored procedure's input parameters

System.out.println("calling stored procedure . . .");
for (int i = 0; i < bean.getAppName().length; i++)
{


cstmt.setString(1, bean.getAppName()[i]);
cstmt.setString(2, bean.getBasepath()[i]);
cstmt.setString(3, bean.getDesc()[i]);
cstmt.setString(4, bean.getUsername());

//output params in sql
cstmt.registerOutParameter(5, Types.INTEGER);
cstmt.registerOutParameter(6, Types.INTEGER);
cstmt.registerOutParameter(7, Types.VARCHAR);
cstmt.registerOutParameter(8, Types.VARCHAR);
cstmt.execute();
}
//now that the input parameters are set, we can proceed to execute the insertTheForm stored procedure

cstmt.close();
System.out.println("Stored procedure executed succesfully.....");
}

catch (SQLException e)
{
System.out.println("error: " + e);
e.printStackTrace();

}

return nbean;
}
}
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Welcome to JavaRanch!

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.

Also, please see the JavaRanch naming policy and change your display name to conform with this policy. Thanks!

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is this actually a Struts 2 question, or a JDBC question? Assuming the values are getting to the action correctly, it seems more the latter, thus in the wrong forum.
 
jQuery in Action, 2nd edition
 
subject: Insertion Values not get stored in sql server using stored procdure in struts2