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
10 4669
What?
Are you talking about maybe providing a different connection string in order to connect to the database?
Maybe based on user provided credentials?
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? -
@WebService()
-
public class Name {
-
-
@Resource(name = "DB")
-
private DataSource DB;
-
String pass1 = "";
-
String mail = "";
-
String q = "";
-
String a = "";
-
Statement statement = null;
-
ResultSet rs = null;
-
int updateQuery = 0;
-
/**
-
* Web service operation
-
*/
-
@WebMethod
-
public String hi(@WebParam(name = "name") String name, @WebParam(name = "sname") String sname) {
-
-
try {
-
-
Connection con = DB.getConnection();
-
statement = con.createStatement();
-
String query = "Select * from where CUST__NAME ="+name+"and CUST__SURNAME = "+sname;
-
rs = statement.executeQuery(query);
-
-
-
while(rs.next()){
-
pass1 = rs.getString("CUST__PASS1");
-
mail = rs.getString("CUST__MAIL");
-
q = rs.getString("CUST__QUESTION");
-
a = rs.getString("CUST__ANSWER");
-
-
}
-
rs.close();
-
statement.close();
-
con.close();
-
} catch (SQLException ex) {
-
ex.printStackTrace();
-
}
-
-
-
return "Hello "+name+" "+sname+ " Your password is "+pass1+ " and your e-mail is "+mail + ". Yout question is "+q+" and your answer is "+a;
-
-
}
-
-
}
-
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: - String query = "Select * from TableName where CUST__NAME ="+name+"and CUST__SURNAME = "+sname;
i tried now -
@WebMethod
-
public String hi(@WebParam(name = "name") String name, @WebParam(name = "sname") String sname) {
-
-
try {
-
-
Connection con = DriverManager.getConnection ("jdbc:odbc:Antique");
-
statement = con.createStatement();
-
String query = "Select * from CUSTOMER where CUST__NAME ="+name+"and CUST__SURNAME = "+sname;
-
rs = statement.executeQuery(query);
-
-
-
while(rs.next()){
-
pass1 = rs.getString("CUST__PASS1");
-
mail = rs.getString("CUST__MAIL");
-
q = rs.getString("CUST__QUESTION");
-
a = rs.getString("CUST__ANSWER");
-
-
}
-
rs.close();
-
statement.close();
-
con.close();
-
} catch (SQLException ex) {
-
ex.printStackTrace();
-
}
-
-
-
return "Hello "+name+" "+sname+ " Your password is "+pass1+ " and your e-mail is "+mail + ". Yout question is "+q+" and your answer is "+a;
-
-
}
-
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?
Your select statement still isn't right.
I think it should be: - "Select * from CUSTOMER where CUST__NAME ='"+name+"' and CUST__SURNAME = '"+sname+"'";
changed the sql statment, driver is connected to db and still doesn't work
even changed the coding -
@WebMethod
-
public String hi(@WebParam(name = "name") String name, @WebParam(name = "sname") String sname) {
-
-
getDBInfo(name,sname);
-
return qt;
-
-
}
-
-
public void getDBInfo(String name, String sname)
-
{
-
try {
-
-
Connection con = DriverManager.getConnection ("jdbc:odbc:Antique","","");
-
statement = con.createStatement();
-
String query = "Select * from CUSTOMER where CUST__NAME ='"+name+"' and CUST__SURNAME = '"+sname+"'";
-
rs = statement.executeQuery(query);
-
-
-
while(rs.next()){
-
pass1 = rs.getString("CUST__PASS1");
-
mail = rs.getString("CUST__MAIL");
-
q = rs.getString("CUST__QUESTION");
-
a = rs.getString("CUST__ANSWER");
-
-
}
-
con.close();
-
} catch (SQLException ex) {
-
ex.printStackTrace();
-
}
-
-
qt = "Hello "+name+" "+sname+ " Your password is "+pass1+ " and your e-mail is "+mail + ". Yout question is "+q+" and your answer is ";
-
-
}
-
and its all to do with the connection adn sql, coz it still returns all of the string except the sql parts
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
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?
in debug, it says, Connection con is not a know variable in current context, what does that mean?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
| |