Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa WebSevices Creating a web service that connects to the database
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mwamba chishimba
Creating a web service that connects to the database
8 Answer(s)      5 years and 2 months ago
Posted in : WebSevices



Advertisement
View Answers

November 9, 2009 at 3:54 PM


Hi,

Please tell me the table structure and other details. I will provide you the example tomorrow.

Regards
Deepak Kumar


November 9, 2009 at 7:00 PM


Thank You Deepak for your quick response.

Like I mentioned, I have an access database. This particular operation is only affecting the customers table which has the following fields:

Username (PK)
Firstname
Lastname
Location (FK)
Phonenumber
Physical address
CreditCardNumber
DrivingLicenceNumber

When registering online, they supply these details through a webservice. Let me know if you need further details. Again, am very grateful for you help!

Kind Regards,


November 10, 2009 at 10:24 PM


HI Deepak, my sincere apologies for sounding so desperate maybe I am and you not the one to blame.

Just want to find out if by any chance you had time to look into my problem.

Than you once again for your help.

Kind Regards,

Mwamba.


November 11, 2009 at 1:03 AM


Hi Deepak,

U though we could start from somewhere so I followed one of the tutorials I found on this awesome site. I followed it quite literally and went through all the processes and procedures. However I was an unable to insert the record I had created.

I have appended the results I got.



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package pack1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.sql.DataSource;

/**
*
* @author Ba Mwamba
*/
@WebService()
public class customer {
@Resource(name = "customer")
private DataSource customer;

/**
* Web service operation
*/
@WebMethod(operationName = "Create")
public String Create(@WebParam(name = "username")
String username, @WebParam(name = "drivinglicence")
String drivinglicence, @WebParam(name = "creditcard")
String creditcard, @WebParam(name = "firstname")
String firstname, @WebParam(name = "lastname")
String lastname, @WebParam(name = "physicaladdress")
String physicaladdress, @WebParam(name = "phonenumber")
String phonenumber, @WebParam(name = "password")
String password, @WebParam(name = "location")
String location, @WebParam(name = "Registrationdate")
String Registrationdate) {
//TODO write your implementation code here:
String status = "Record not inserted";
try
{
Connection con= customer.getConnection();
PreparedStatement ps=con.prepareStatement("INSERT INTO Customer VALUES(?,?,?,?,?,?,?,?,?,?)");
ps.setString(1, username);
ps.setString(2, drivinglicence);
ps.setString(3, creditcard);
ps.setString(4, firstname);
ps.setString(5, lastname);
ps.setString(6, physicaladdress);
ps.setString(7, phonenumber);
ps.setString(8, password);
ps.setString(9, location);
ps.setString(10, Registrationdate);
int i = ps.executeUpdate();
if(i!=0)
{
status="Record Inserted";
}
}catch(Exception e){
System.out.println("Error in storing data"+e);
}
return status;
}

}




Results from the above operation:





create Method invocation


Method parameter(s)

Type Value
java.lang.String mwamba
java.lang.String 123456789
java.lang.String 98765443
java.lang.String mwamba
java.lang.String chishimba
java.lang.String 48/50A Makeni
java.lang.String 098765433
java.lang.String mwamba
java.lang.String L002
java.lang.String 10/11/2009
Method returned

java.lang.String : "Record not inserted"
SOAP Request

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">;
<S:Header/>
<S:Body>
<ns2:Create xmlns:ns2="http://pack1/">;
<username>mwamba</username>
<drivinglicence>123456789</drivinglicence>
<creditcard>98765443</creditcard>
<firstname>mwamba</firstname>
<lastname>chishimba</lastname>
<physicaladdress>48/50A Makeni</physicaladdress>
<phonenumber>098765433</phonenumber>
<password>mwamba</password>
<location>L002</location>
<Registrationdate>10/11/2009</Registrationdate>
</ns2:Create>
</S:Body>
</S:Envelope>
SOAP Response

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">;
<S:Body>
<ns2:CreateResponse xmlns:ns2="http://pack1/">;
<return>Record not inserted</return>
</ns2:CreateResponse>
</S:Body>
</S:Envelope>


Where I am going wrong?

Kind Regards,


November 11, 2009 at 5:05 PM


Hi,

Please check the complete tutorial at http://roseindia.net/webservices/web-services-database.shtml

Let me know if you face any problem.

Regards
Deepak Kumar


November 11, 2009 at 7:13 PM


Thank you Deepak am sure this will be very helpful.

Just a quick question. I already have a connection to my database through a DAO class which is controlling the system interaction with the database and it is working just fine. Do I still need to create the connection in the webservice class as you are suggesting.
here is the code from my dao class:

import java.sql.*;
public class DAO
{
Connection con=null;
Statement st=null;
ResultSet rs=null;
public DAO()
{

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url= new String("jdbc:odbc:CarHire");
con=DriverManager.getConnection(url,"","");
st=con.createStatement();

}
catch(Exception e)
{
System.out.print("Error:" + e);
}
}

with this dao in place all am doing is call the dao from my my servlets and pass appropriate parameters to it and it does what i have defined in the dao class.

I have tried to call the dao in the webservice class but gives an error owing to the fact that it's in another package.

is it possible for me to use this connection i have already defined or do i need to create one specifically for the webservice?

Kind Regards,

Mwamba.



November 12, 2009 at 2:23 AM


Hi Deepak,

I want to sincerely thank you for your kindness and patience you shuold towards me!! Trust me, I can't thank you enough for what you have done for me.

So the code did manage to work but only after I changed from the preparedstatement to just statement and it worked perfectly well.

May God continue to prosper you in all what you do and I hope we can be "programming friends :)".

thank you one again!!

with kind regards,

Mwamba Chishimba.


September 17, 2013 at 1:09 AM


Hi All,

This is an interesting post which is more useful for me as well. I need to show the results on UI by calling the service which interacts with the DB. The results are Name, ID, Address, Contact Number etc. Someone please provide me the same Axis2 service.

Best Regards Varma



Related Tutorials/Questions & Answers:
Creating a web service that connects to the database - WebSevices
Creating a web service that connects to the database  Hello, Good... DataSource customer; /** * Web service operation... be achieved especially the creation of accounts and then saving to the database
web service & database
web service & database  Hi, I need help with importing data from web service to ms sql/my sql. I developed a web service using Axis2 (v1.6.2) and Tomcat (v7.0.27) running on Eclipse Indigo. I can connect to the web services
Advertisements
Creating a service - JSP-Servlet
Creating a service  I created a database for username and password nd...) to get the data back from the database.(Service is a seperate class not like... page.Then I created a DAO class which would access the database and return
web service
web service  i want to make an web service example so please help me out thanks  
web service
would be grateful :):) So i want to creat a web service that display the bus... coordinate will be send to my web service in a array list but i cant translate this into a code; my problem is in the web service side : in wich class i will do
Web Service
Web Service  Dear Sir, My code is :- For webService:- import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService..."; ServiceFactory factory = ServiceFactory.newInstance(); Service service
Web Service
Web Service  Dear Sir, My code is :- For webService:- import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService..."; ServiceFactory factory = ServiceFactory.newInstance(); Service service
Web service
Web service  webservices in JSP
web service
web service  How servlet class create in web services or how html code used in webservice. pls give example which contain servlet code
web service
web service  How servlet class create in web services or how html code used in webservice. pls give example which contain servlet code
creating windows service - RMI
creating windows service  Hi, I have created a project using spring RMI and have some server.jar file which contians all the classes of server... service for this server so that it can start/stop at any time. please help me
xcode web service example
xcode web service example  xcode web service example
Web Service Tutorial - WebSevices
the attachment of a step by step procedure of creating web service. Thanks and Regards...Web Service Tutorial  hi, i am asking you again for my previous question of web service. you told me about a link but there is no link in your
Web Service Tutorial - WebSevices
the steps of creating a simple web service. Thanks and Regards Nishi...Web Service Tutorial  hi, i am new to web service and not much have idea about web services. right now i am using myeclipse blue 7.1 as my java IDE
Web service protocol stack
Web service protocol stack  hii, What is the Web service protocol stack?   hello, The Web service protocol stack is an evolving set of protocols used to define, discover, and implement Web services
Create a Web Service in Java using Apache Axis2 and Eclipse with Oracle database driven
Create a Web Service in Java using Apache Axis2 and Eclipse with Oracle... a requirement of connecting an external system using web service developed which uses eclipse ID and Apache axis 2 services. The web service should be based on bottom-up
Web Service - WebSevices
Web Service  Hi All I have web service in .net , and i have to call it from java spring. How can i do it? Thanks
web service protocols
Web service Protocols         Web service protocols: Here is the list of some protocols used for Web Services
web service frameworks
Web service Frameworks         Web service Frameworks: There are many frameworks for web services. Here is the list of some frameworks
web service client
web service client  i have implement web service client in netbeans and it work will using wsdl but know i want to Develop a webserivce (or a Java RMI server/client) for one of the e-services but i do not know the wsdl link how
web service - JSP-Servlet
web service  How to call a web service from JSP post method?  Method in JSPHi! In this JSP Example you'll see, how to call web service from JSP methodName the file as usingMethod.jsp JSP Code- - - - -<%@ page
web service problem - WebSevices
web service problem  I have created web service client and server for File transfering using axis2/java.I want to add JAX-RPC client Handler...; Thank u....Actually web service without client handler is working. I want
Spring web service - Spring
Spring web service   Respected service, I have found an error in this manner(Connecting to tomcat then coming this error at first time only) and then working correctly. error coming only at first time. What
How to Convert SOAP Web service to REST Web service In Java ?
How to Convert SOAP Web service to REST Web service In Java ?  I want to Convert SOAP Web service(WSDL) to REST web service in JSON Format with GET... service. What I know is that JAX-RS api is used to generate REST Web service
Java - Web Service
Java - Web Service code that allow the user to input file name with path  Hi, I wanted a simple java program for web services development as per below: ------ IN REQUEST ------ <FileName> FileName - Path
Fedex web service
Fedex web service  sir how can use fedex api
creating web services - WebSevices
stopped publish Window II. Steps for Creating Web Service 1.Create a new Dynamic...creating web services  Actually i am new for web services so Plz tell... or test the web service on Apache Tomcat v5.5 server. This section also provide step
developing simple web service
Open Source web services tool in java   ...: The Web Services Invocation Framework (WSIF) is a simple Java API for invoking Web services, no matter how or where the services are provided
Java - Web Service
Java - Web Service  Hi, I wanted a simple java program for web services development as per below: ------ IN REQUEST ------ <FileName> FileName - Path of the file (For example: C/text.txt) ------ IN RESPONSE
Java - Web Service
Java - Web Service  Hi, I wanted a simple java program for web services development as per below: ------ IN REQUEST ------ <FileName> FileName - Path of the file (For example: C/text.txt) ------ IN RESPONSE
web service call in jsp page
web service call in jsp page  I am wandering on internet for hours... a web service when you have a WSDL. I am using tomcat web server and eclipse ,a simple example to demostrate the web service calling would be good for me... I
 

 

 

DMCA.com