Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7768085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:49:55+00:00 2026-06-01T15:49:55+00:00

I am new to web services. Please give suggestions how to insert and retrieve

  • 0

I am new to web services. Please give suggestions how to insert and retrieve data from database using jersey JAX – RS in java?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:49:57+00:00Added an answer on June 1, 2026 at 3:49 pm

    Below is an example of a JAX-RS service implemented as a session bean using JPA for persistence and JAXB for messaging might look like.

    CustomerService

    package org.example;
    
    import java.util.List;
    
    import javax.ejb.*;
    import javax.persistence.*;
    import javax.ws.rs.*;
    import javax.ws.rs.core.MediaType;
    
    @Stateless
    @LocalBean
    @Path("/customers")
    public class CustomerService {
    
        @PersistenceContext(unitName="CustomerService",
                            type=PersistenceContextType.TRANSACTION)
        EntityManager entityManager;
    
        @POST
        @Consumes(MediaType.APPLICATION_XML)
        public void create(Customer customer) {
            entityManager.persist(customer);
        }
    
        @GET
        @Produces(MediaType.APPLICATION_XML)
        @Path("{id}")
        public Customer read(@PathParam("id") long id) {
            return entityManager.find(Customer.class, id);
        }
    
        @PUT
        @Consumes(MediaType.APPLICATION_XML)
        public void update(Customer customer) {
            entityManager.merge(customer);
        }
    
        @DELETE
        @Path("{id}")
        public void delete(@PathParam("id") long id) {
            Customer customer = read(id);
            if(null != customer) {
                entityManager.remove(customer);
            }
        }
    
        @GET
        @Produces(MediaType.APPLICATION_XML)
        @Path("findCustomersByCity/{city}")
        public List<Customer> findCustomersByCity(@PathParam("city") String city) {
            Query query = entityManager.createNamedQuery("findCustomersByCity");
            query.setParameter("city", city);
            return query.getResultList();
        }
    
    }
    

    Customer

    Below is an example of one of the entities. It contains both JPA and JAXB annotations.

    package org.example;
    
    import java.io.Serializable;
    import javax.persistence.*;
    import javax.xml.bind.annotation.XmlRootElement;
    
    import java.util.Set;
    
    @Entity
    @NamedQuery(name = "findCustomersByCity",
                query = "SELECT c " +
                        "FROM Customer c " +
                        "WHERE c.address.city = :city")
    @XmlRootElement
    public class Customer implements Serializable {
        private static final long serialVersionUID = 1L;
    
        @Id
        private long id;
    
        @Column(name="FIRST_NAME")
        private String firstName;
    
        @Column(name="LAST_NAME")
        private String lastName;
    
        @OneToOne(mappedBy="customer", cascade={CascadeType.ALL})
        private Address address;
    
        @OneToMany(mappedBy="customer", cascade={CascadeType.ALL})
        private Set<PhoneNumber> phoneNumbers;
    
    }
    

    For More Information

    • Part 1 – Data Model
    • Part 2 – JPA
    • Part 3 – JAXB (using MOXy)
    • Part 4 – RESTful Service (using an EJB session bean)
    • Part 5 – The client

    UPDATE

    what are the jars required

    You can deploy a JAX-RS/EJB/JPA/JAXB application to any Java EE 6 compliant application server without requiring any additional server set up. Programming the client you can get the JAX-RS APIs from the Jersey (http://jersey.java.net/), and the JPA and JAXB APIs from EclipseLink (http://www.eclipse.org/eclipselink/).

    and where the database connections is written

    JDBC Resource & Connection Pool

    You need to configure a connection pool on your application server. Below are the steps to do this on GlassFish. The steps will vary depending on the application server you are using.

    1. Copy the JDBC driver (ojdbc14.jar) to /glashfish/lib
    2. Launch the Administration Console
    3. Create a Connection Pool:
      1. Name = CustomerService
      2. Resource Type = ‘javax.sql.ConnectionPoolDataSource’
      3. Database Vendor = Oracle (or whatever database vendor is appropriate to your database)
      4. Click Next and fill in the following “Additional Properties”:
      5. User (e.g. CustomerService)
      6. Password (e.g. password)
      7. URL (e.g. jdbc:oracle:thin:@localhost:1521:XE)
      8. Use the “Ping” button to test your database connection
    4. Create a JDBC Resource called “CustomerService”
      1. JNDI Name = CustomerService
      2. Pool Name = CustomerService (name of the connection pool you created in the previous step)

    JPA Configuration

    Then we reference the database connection we created above in the persistence.xml file for our JPA entities as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0"
        xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
        <persistence-unit name="CustomerService" transaction-type="JTA">
            <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
            <jta-data-source>CustomerService</jta-data-source>
            <class>org.example.Customer</class>
            <class>org.example.Address</class>
            <class>org.example.PhoneNumber</class>
            <properties>
                <property name="eclipselink.target-database" value="Oracle" />
                <property name="eclipselink.logging.level" value="FINEST" />
                <property name="eclipselink.logging.level.ejb_or_metadata" value="WARNING" />
                <property name="eclipselink.logging.timestamp" value="false"/>
                <property name="eclipselink.logging.thread" value="false"/>
                <property name="eclipselink.logging.session" value="false"/>
                <property name="eclipselink.logging.exceptions" value="false"/> 
                <property name="eclipselink.target-server" value="SunAS9"/> 
            </properties>
        </persistence-unit>
    </persistence>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Java web-services and am working on one currently, using Apache
I'm pretty new to Web Services in java. I was starting on a project
Im pretty new to Java Web Services, but I cant find a good explanation
I'm new to Java Web Services, so I might be doing things wrong. I'm
I m new to using Web services using JavaScript. All I want is to
Please forgive if i use terminology wrong, but i'm new to java-web development and
I am new to web services. I need to get information from .NET web
I'm new to both web services and C# so please forgive me if my
I am new to the web services and using Eclipse indigo to do the
I am totally new to web services and cannot get mine to work. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.