Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server Stored Procedures

Status
Not open for further replies.

Shilohcity

Technical User
Jul 12, 2000
136
GB
Hello

I am trying to run a SQL Server stored procedure from a JSP page and just cant seem to figure out how to do it. I am communicating fine with the d/base and running standard SQL queries with no worries so I think it is just the syntax I am a bit unsure of.

I am a little confused over callable statements etc and also how to obtain a recordset from a stored procedure.

At present my working code looks like this:

Driver MM_driver = (Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection myConn = DriverManager.getConnection("jdbc:weblogic:mssqlserver4:web_test@mydatabase",MM_editUserName,MM_editPassword);
Statement stmt = myConn.createStatement();//(MM_editQuery.toString());
ResultSet myResultSet = stmt.executeQuery("select * from test_table");

if (myResultSet != null)

{
while (myResultSet.next()) {
String eid = myResultSet.getString("id");

%>
hello<%= eid %>
<%

}
}

myConn.close();
}
}
%>

All help and suggestions most appreciated in my time of need.

Thanks
Justin. X-) &quot;Creativity is the ability to introduce order into the randomness of nature.&quot; Eric Hoffer

Visit me at
 

hi

1) create a callable statement object :

CallableStatement cstmt = myConn.prepareCall(&quot;{? = call procedurename(arg1,arg2,...) }&quot;);

2) register OUT parameters. see doc for CallableStatement

3) set IN parameters.

ex : cstmt.setInt(index of parameter in the list of arguments, value (here an int))

much setXXX methods exists for all SQL types (String, Double...)

3) execute query

cstmt.execute()

manu0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top