473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Web service connection

Sl1ver
196 100+
Figured out how the web service interacts with a jsp page. now i just want to know. in the web service when connection to a db it creates a datasource using the jdbc driver that you specified. How do you use that @datasource to connect to the db and interact with the db. (using netbeans 5.5) its a project so i cant use anything else
Oct 5 '09 #1
10 4669
Frinavale
9,735 Expert Mod 8TB
What?

Are you talking about maybe providing a different connection string in order to connect to the database?

Maybe based on user provided credentials?
Oct 6 '09 #2
Sl1ver
196 100+
Ok, i got it so that if i typed my name and surname in two boxes, it calls the web service and then return Hello "Jonathan" "Meyer". Now in that exact piece of code i made it connect to the database and return all information associated to me(compares my name and surname in the sql where clause). here is my code, What am i doing wrong, and is there any alternative to using the jdbc driver that netbeans creates in the web service?
Expand|Select|Wrap|Line Numbers
  1. @WebService()
  2. public class Name {
  3.  
  4.     @Resource(name = "DB")
  5.     private DataSource DB;
  6.     String pass1 = "";
  7.     String mail = "";
  8.     String q = "";
  9.     String a = "";
  10.     Statement statement = null;
  11.     ResultSet rs = null;
  12.     int updateQuery = 0;
  13.     /**
  14.      * Web service operation
  15.      */
  16.     @WebMethod
  17.     public String hi(@WebParam(name = "name") String name, @WebParam(name = "sname") String sname) {
  18.  
  19.         try {
  20.  
  21.         Connection con = DB.getConnection();
  22.         statement = con.createStatement();
  23.         String query = "Select * from where CUST__NAME ="+name+"and CUST__SURNAME = "+sname;
  24.         rs = statement.executeQuery(query);
  25.  
  26.  
  27.              while(rs.next()){
  28.             pass1 = rs.getString("CUST__PASS1");
  29.             mail = rs.getString("CUST__MAIL");
  30.             q = rs.getString("CUST__QUESTION");
  31.             a = rs.getString("CUST__ANSWER");
  32.  
  33.         }
  34.             rs.close();
  35.             statement.close();
  36.             con.close();
  37.         } catch (SQLException ex) {
  38.             ex.printStackTrace();
  39.         }
  40.  
  41.  
  42.         return "Hello "+name+" "+sname+ " Your password is "+pass1+ " and your e-mail is "+mail + ". Yout question is "+q+" and your answer is "+a;
  43.  
  44.     }
  45.  
  46. }
  47.  
Oct 7 '09 #3
Frinavale
9,735 Expert Mod 8TB
Well it looks ok except for the way that you're getting your connection might be incorrect.

Please look at the DriverManager class specifically how to use the DriverManager's getConnection method.

Oh, and your SQL Select statement is wrong. You should be specifying the table to select from.

So Line 23 should look something like:

Expand|Select|Wrap|Line Numbers
  1. String query = "Select * from TableName where CUST__NAME ="+name+"and CUST__SURNAME = "+sname;
Oct 7 '09 #4
Sl1ver
196 100+
i tried now
Expand|Select|Wrap|Line Numbers
  1. @WebMethod
  2.     public String hi(@WebParam(name = "name") String name, @WebParam(name = "sname") String sname) {
  3.  
  4.         try {
  5.  
  6.         Connection con = DriverManager.getConnection ("jdbc:odbc:Antique");
  7.         statement = con.createStatement();
  8.         String query = "Select * from CUSTOMER where CUST__NAME ="+name+"and CUST__SURNAME = "+sname;
  9.         rs = statement.executeQuery(query);
  10.  
  11.  
  12.              while(rs.next()){
  13.             pass1 = rs.getString("CUST__PASS1");
  14.             mail = rs.getString("CUST__MAIL");
  15.             q = rs.getString("CUST__QUESTION");
  16.             a = rs.getString("CUST__ANSWER");
  17.  
  18.         }
  19.             rs.close();
  20.             statement.close();
  21.             con.close();
  22.         } catch (SQLException ex) {
  23.             ex.printStackTrace();
  24.         }
  25.  
  26.  
  27.         return "Hello "+name+" "+sname+ " Your password is "+pass1+ " and your e-mail is "+mail + ". Yout question is "+q+" and your answer is "+a;
  28.  
  29.     }
  30.  
and it still doesn't work. it returns all of the strings plus what i type in, but it doesnt shoe the string its supposed to from the db?
Oct 8 '09 #5
Frinavale
9,735 Expert Mod 8TB
Your select statement still isn't right.
I think it should be:

Expand|Select|Wrap|Line Numbers
  1. "Select * from CUSTOMER where CUST__NAME ='"+name+"' and CUST__SURNAME = '"+sname+"'";
Oct 8 '09 #6
Sl1ver
196 100+
changed the sql statment, driver is connected to db and still doesn't work
even changed the coding
Expand|Select|Wrap|Line Numbers
  1.  @WebMethod
  2.     public String hi(@WebParam(name = "name") String name, @WebParam(name = "sname") String sname) {
  3.  
  4.         getDBInfo(name,sname);
  5.         return qt;
  6.  
  7.     }
  8.  
  9.     public void getDBInfo(String name,  String sname)
  10.     {
  11.         try {
  12.  
  13.         Connection con = DriverManager.getConnection ("jdbc:odbc:Antique","","");
  14.         statement = con.createStatement();
  15.         String query = "Select * from CUSTOMER where CUST__NAME ='"+name+"' and CUST__SURNAME = '"+sname+"'";
  16.         rs = statement.executeQuery(query);
  17.  
  18.  
  19.             while(rs.next()){
  20.             pass1 = rs.getString("CUST__PASS1");
  21.             mail = rs.getString("CUST__MAIL");
  22.             q = rs.getString("CUST__QUESTION");
  23.             a = rs.getString("CUST__ANSWER");
  24.  
  25.         }
  26.             con.close();
  27.         } catch (SQLException ex) {
  28.             ex.printStackTrace();
  29.         }
  30.  
  31.         qt = "Hello "+name+" "+sname+ " Your password is "+pass1+ " and your e-mail is "+mail + ". Yout question is "+q+" and your answer is ";
  32.  
  33.     }
  34.  
Oct 8 '09 #7
Sl1ver
196 100+
and its all to do with the connection adn sql, coz it still returns all of the string except the sql parts
Oct 8 '09 #8
Frinavale
9,735 Expert Mod 8TB
Well, have you taken the time to step through your application to see what's going on?

Are you getting any error messages?

Have you tested the SQL statement using a database tool before using it in your application (using a tool like Hiedi)?

-Frinny
Oct 8 '09 #9
Sl1ver
196 100+
if i run the sql from netbeans , it returns all the data, i dont know how to step through it, isnt it a web service and doesn't allow for step through?
Oct 8 '09 #10
Sl1ver
196 100+
in debug, it says, Connection con is not a know variable in current context, what does that mean?
Oct 8 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: epaetz | last post by:
I'm getting Not associated with a trusted SQL Server connection errors on a .Net windows service I wrote, when it's running on my application server. It's not a problem with mixed mode...
2
by: JD | last post by:
Hello, I'm experiencing a problem that I'm hoping someone might be able to shed some light on. I have an ASP.NET page on a Windows 2000 machine that makes web service calls to a .NET web...
10
by: amirmira | last post by:
I have a Windows Service developed in VB.NET that attempts to connect to a database as soon as the service starts. I have no problem when I start the service manually - but when I restart the...
3
by: danavni | last post by:
i need to build a service that will accept incoming TCP/IP connections. the service should act like a "HUB" where on one side clients connect to it and stay connected for as long as they like and...
3
by: Hans Merkl | last post by:
Hi, I am helping to build a web app that's pretty much a wrapper around a web service. The question now is how to store the handle of the web service object between requests. My client is using...
8
by: nautonnier | last post by:
I know my problem has been discussed ad nauseum but I still don't get it so please bear with me. I have written a service which performs some work against a database once a day (usually in the...
0
by: Emanuele | last post by:
I have write a program using MS Visual studio C++ 7.0 (platform Windows XP professional). I'm not using .NET. This program save data in a SQL server 2000 database using ADO. Everything works...
3
by: sonu | last post by:
Hello all, I am trying to develop an application which will run as a windows service. The application should have Normal options available with service like start, stop and pause but along...
0
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my...
0
by: =?Utf-8?B?UmljaGFyZCBC?= | last post by:
We have been receiving a connection error at one of our sites, our application works elsewhere. The error occurs when our application written in vb.net 2.0 running as a Windows Service under the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.