WebService with database Mysql - A database driven webservice
User Registration WebServices Example
In this tutorial we will develop a simple user registration
Webservices. The user registration/account registration form will be
presented to the user. Once user fills in the form and clicks on the
"OK" button, the serverside JSP will call the webservice to
register the user.
This webservices will expose the insert user operation which will be
used by the JSP client to register the user. We will use the NetBeans
6.1 IDE to develop and test the application.
The MySQL database is used to save the user registration data. You can
modify the code to use any database of your choice. The existing
webservices can also be modified to use the Hibernate or any other ORM
technologies. You can also use the Entity beans to persist the data
Software required to develop and run this example:
MySQL Database 5 or above
Let's get started with the development of the applicaton
Configuration In NetBeans
Let's configure MySQL database in teh NetBeans IDE and then create the
required table into database.
Click on the service tab in NetBeans as shown
below in Fig 1.
Right Click on the Databases
Select New Connection as shown below in Fig 2.
It opens a dialog box for the mysql configuration.
Type the driver name, url , user name and password as shown
below in Fig. 3.
3 Step 4:
Click on the Ok button .
Now expand the Newly created database connection.
It shows the all the tables of the database test as shown
below in Fig 4.
Create a table named login.
Right Click on the Tables and select Create table
as shown below in Fig 5
5 Step 6:
It opens a dialog box for giving the fields name of the
Now give the field name and data type as shown below in Fig
Click on the Ok
It creates the table login in the test database.
WebService program for Account creation
Open the netbeans 6.1
Creat a new web project as shown below in Fig 7.
Type the project Name as MyAccount
Click on the next button as shown below in Fig 8.
Select the server as Glassfish
Click on the Next and then finish button as shown below in
Fig. 9 Step 11:
It creates a Web Project named MyAccount.
Right Click on the project MyAccount
Select New-->WebService as shown below in
Type the name of the WebService as myaccount with the
package as mypack.
Click on the Finish button as shown below in Fig 11.
It creates a WebService application in
Click on the Add operation as shown below in Fig 12.
Fig. 12 Step 15:
In the dialog box type all parameter
Also select the appropriate data type.
Click on Ok as shown below in Fig 13.
Fig. 13 Step 16:
It creates a WebService application
Click on the source tab as shown below in the Fig 14.
Fig. 14 Step 17:
Now create the database source
Right Click in the source code of myaccount.java
Select the Enterprise Resources-->Use Database as
shown below in Fig 15.
Fig. 15 Step 18:
In the choose database select the Add button as
shown below in Fig 16.
It opens a Add Data Source Reference.
Type the Reference Name as data1
For Project Data Sources Click on the Add button
as shown below in Fig 17.
In the Crea Data Source type thye jndi name as
In the database connection select the newly
created database connction for the mysql.
as shown below in Fig 18.
Click on the Ok button
It creates the database connection gives the dialog box
as shown below.
Click on the Ok button as shown below in Fig 19.
It creates the datasource data1 with the resource name as
data1 in the code
Edit the code and give the database connection, statement
for the mysql connectivity
as shown below.
June 22, 2012
affiche les donnÃ¨e de basse de donnÃ¨e select *from client
July 5, 2012
wsdl and databases
this is really helpful!!!! thank you a lot!!!!
October 8, 2012
Displays record inserted but mysql table empty
Hi thats a very nice tutorial, the web service part works however am having problems with the client part, after clicking on the ok button, it tells me record inserted, but when i check in the login table there is a new row, but the field are empty. No data is there!
Am using netbeans7.0 and glassfish v3.0 java EE 5 and mysql 5.2. Please help.
July 18, 2013
every thing is wrong....can't do anything...
June 21, 2014
I did same as u did in tutorial but I am not able to see the values in the table.In output it showed the values are inserted perfectly
August 7, 2014
is this SOAP based or Restful?
August 8, 2014
The records are not being updated in the database
What may be the solution?
August 8, 2014
Posting in database
The values are not updated in the database
March 22, 2012
EJB Methods And Enterprise Resources menu options
I think what you are looking can be found by:
- right clicking in the editor
- clicking insert code...
- there is then an option for call enterprise bean as well as the other options that used to be in the ENterprise Resources menu
Hope this helps.