wood burning stoves 2.0*
The moose likes Web Services and the fly likes Replace JDBC calls with webservices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Replace JDBC calls with webservices" Watch "Replace JDBC calls with webservices" New topic
Author

Replace JDBC calls with webservices

Josweth Reddy
Ranch Hand

Joined: Nov 02, 2005
Posts: 30
Hi All,

I need to replace the JDBC calls with webservices.

Code:

public String getName(int userId){

String userName=null;

String stmt="select user_name from USER where user_id='userId'"

//execute the query and get the username

return userName;
}

In the above code I need to repalce the JDBC calls with webservices.

Please help me out to solve this and suggest the best way I can do it so.

Thanks,
Reddy.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Write a Web services which does JDBC call.


//execute the query and get the username
Write the WS call here


Groovy
Josweth Reddy
Ranch Hand

Joined: Nov 02, 2005
Posts: 30
Thanks Prad Dip,

Actually Im a new bee to web services. Can you please explain in detail with some example/code.

Thanks,
Reddy. :roll:
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Check this
http://faq.javaranch.com/java/WebServicesFaq
Josweth Reddy
Ranch Hand

Joined: Nov 02, 2005
Posts: 30
Hi Prad Dip,

Gone through the URLs but didnt get info related to JDBC calls in webservices. Please explain the approach with example/code.

Thanks,
Reddy :roll:
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41180
    
  45
There's nothing JDBC-specific about web services. You need to create and call a WS that takes a userID parameter, and which then returns the user name -if any- that goes along with it. So the JDBC code would be in the WS implementation class (presumably the WS somehow knows which DB to access, and has the required passwords etc.).

Is this the only DB call you need to make? In general, it doesn't seem like a good idea to access a DB remotely through a WS. Why does it need to be a WS?


Ping & DNS - my free Android networking tools app
Josweth Reddy
Ranch Hand

Joined: Nov 02, 2005
Posts: 30
Hi Ulf,

Thanks for the inputs.

Let me explain my requirement first.

Here we have an application(XYZ) with some JDBC calls. Now there is a need to replace these JDBC calls with webservices.

Based on your explanation, I usnderstood that

1) Need to create a web service which takes the userid as input and retruns user name.

2) Need to invoke the webservice from the class where I have JDBC code previously (in XYZ application).

3) In the webservice implementation class, need to place the existing JDBC code and return the user name as response of the webservice. (webservice implementation class Contains all the DB inforamtion like UN, Passwods ..etc)

Requesting you to correct me if I'm deviating/wrong.


As per the requirement,by using webservices we need to execute the statements and stored procedures. Can you please suggest me the best approach, if any.


Thanks,
Reddy
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41180
    
  45
Well, I was asking why you need to replace JDBC with WS. It just doesn't seem like a good idea, especially not if you have several JDBC calls.

What kind of application is this - a desktop app? Why can't it use JDBC? Does the app run outside of a firewall?
Josweth Reddy
Ranch Hand

Joined: Nov 02, 2005
Posts: 30
Hi Ulf,

Yes, I have several JDBC calls(like SELECT, INSERT, UPDATE ..etc and stored procedures also) in my application.
This is a web application.


Is the above mentioned approach correct, if there are more JDBC calls ? As per the requirement, Webservices need to interact with some other applications also.

Suggest me if there is any alternate or if I'm wrong.

Thanks,
Reddy
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41180
    
  45
You keep saying that it's a requirement, but I'm asking why it's a requirement. If it's a web app, then in all likelihood the database is on the same network as the web app, which makes the whole exercise a bit pointless, IMO. So I'm thinking I'm missing something - that's why I'm asking why it needs to be done.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Why do you want an extra layer of WS which would cause some performance drop and unnecessary XML communication.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Replace JDBC calls with webservices
 
Similar Threads
UltraDev JSP Help
java.lang.IllegalArgumentException: Parameter UserName does not exist
How to remove duplicate from ArrayList?
unable to pass value of resultset to servlet to jsp
How can i get session data into business objects.