Calling stored procedures from server side !

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Calling stored procedures from server side !

Postby faisal007 » 02 Dec 2016, 07:43

Hi,

Is there a way to call stores procedures and database functions on server side ? Basically we want to write no queries, instead stored procedures will be helpful.

Any links or recipes ?

Thanks.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Calling stored procedures from server side !

Postby Lapo » 02 Dec 2016, 08:16

Hi,
we don't have specific recipes because stored procedures differ based on the database of your choice.
In a nutshell you just need to use JDBC directly instead of our DBManager API. In other words you can obtain the database connection from the DBManager:

Code: Select all

connection = dbManager.getConnection();

Then call your stored procedures with a code like this:

Code: Select all

cs = connection.prepareCall("{call SHOW_SUPPLIERS()}");
ResultSet rs = cs.executeQuery();

while (rs.next()) {
    String supplier = rs.getString("SUP_NAME");
    String coffee = rs.getString("COF_NAME");
    System.out.println(supplier + ": " + coffee);
}

The example is taken from this article from Oracle:
https://docs.oracle.com/javase/tutorial ... dures.html
which illustrates how to create and use stored procedures in Java.

Finally make sure to handle the life cycle of the database connection correctly using a try/catch/finally block to trap exceptions and close the connection at the end of the query process.
See the "Handling Exceptions" section here:
http://docs2x.smartfoxserver.com/Develo ... se-recipes

hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Re: Calling stored procedures from server side !

Postby faisal007 » 02 Dec 2016, 13:18

Hi,

Thanks for the reply !

I will try it out and will post results thanks.
User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Re: Calling stored procedures from server side !

Postby faisal007 » 07 Feb 2017, 16:06

It is working, thanks.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 48 guests