• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Replace JDBC calls with webservices

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a Web services which does JDBC call.


//execute the query and get the username
Write the WS call here
 
Josweth Reddy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this
http://faq.javaranch.com/java/WebServicesFaq
 
Josweth Reddy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Josweth Reddy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you want an extra layer of WS which would cause some performance drop and unnecessary XML communication.
 
They weren't very bright, but they were very, very big. Ad contrast:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic