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 8810509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:08:10+00:00 2026-06-14T03:08:10+00:00

I am new to java technology so please excuse me if I present a

  • 0

I am new to java technology so please excuse me if I present a silly problem…

I want to make a JSF 2.0 servlet and use MySql for database engine.

The problem is that it’s seems that I can’t connect to server.

I use netbeans IDE, and for guide I use a tutorial from youtube: http://www.youtube.com/watch?v=UBNaiVWwAZw&feature=related

The difference is that I use Tomcat.

My persistence.xml file is in Web/META-INF/persistence.xml and the content is:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
  <persistence-unit name="AnunturiJsfPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>my.servlets.Users</class>
    <class>my.servlets.UsersSessions</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/tz_cadastru_galati"/>
      <property name="javax.persistence.jdbc.password" value=""/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="root"/>
    </properties>
  </persistence-unit>
</persistence>

my servlet file is:

package my.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name = "testOkServlet2", urlPatterns = {"/testOkServlet2"})
public class testOkServlet2 extends HttpServlet {


    @PersistenceUnit
    EntityManagerFactory emf;


    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
                EntityManager em = emf.createEntityManager();
                Users u = (Users) em.createNamedQuery("Users.findAll").getResultList().get(0);
                String myUser = u.getUserNume();
                out.println("User:" + myUser);
        } catch (Exception e)
        {
            out.println(e.getMessage());
        }
        finally {           
            out.close();
        }
    }


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }


    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

and this is my Users object:

package my.servlets;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;


@Entity
@Table(name = "users")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
    @NamedQuery(name = "Users.findByUserID", query = "SELECT u FROM Users u WHERE u.userID = :userID"),
    @NamedQuery(name = "Users.findByUserNume", query = "SELECT u FROM Users u WHERE u.userNume = :userNume"),
    @NamedQuery(name = "Users.findByNumePrenume", query = "SELECT u FROM Users u WHERE u.numePrenume = :numePrenume"),
    @NamedQuery(name = "Users.findByEmail", query = "SELECT u FROM Users u WHERE u.email = :email"),
    @NamedQuery(name = "Users.findByParola", query = "SELECT u FROM Users u WHERE u.parola = :parola"),
    @NamedQuery(name = "Users.findByContActiv", query = "SELECT u FROM Users u WHERE u.contActiv = :contActiv"),
    @NamedQuery(name = "Users.findByDataAdaugarii", query = "SELECT u FROM Users u WHERE u.dataAdaugarii = :dataAdaugarii"),
    @NamedQuery(name = "Users.findByNivelAccesID", query = "SELECT u FROM Users u WHERE u.nivelAccesID = :nivelAccesID")})
public class Users implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "userID")
    private Integer userID;
    @Basic(optional = false)
    @Column(name = "userNume")
    private String userNume;
    @Basic(optional = false)
    @Column(name = "numePrenume")
    private String numePrenume;
    @Basic(optional = false)
    @Column(name = "email")
    private String email;
    @Basic(optional = false)
    @Column(name = "parola")
    private String parola;
    @Basic(optional = false)
    @Column(name = "contActiv")
    private boolean contActiv;
    @Basic(optional = false)
    @Column(name = "dataAdaugarii")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dataAdaugarii;
    @Basic(optional = false)
    @Column(name = "nivelAccesID")
    private short nivelAccesID;

    public Users() {
    }

    public Users(Integer userID) {
        this.userID = userID;
    }

    public Users(Integer userID, String userNume, String numePrenume, String email, String parola, boolean contActiv, Date dataAdaugarii, short nivelAccesID) {
        this.userID = userID;
        this.userNume = userNume;
        this.numePrenume = numePrenume;
        this.email = email;
        this.parola = parola;
        this.contActiv = contActiv;
        this.dataAdaugarii = dataAdaugarii;
        this.nivelAccesID = nivelAccesID;
    }

    public Integer getUserID() {
        return userID;
    }

    public void setUserID(Integer userID) {
        this.userID = userID;
    }

    public String getUserNume() {
        return userNume;
    }

    public void setUserNume(String userNume) {
        this.userNume = userNume;
    }

    public String getNumePrenume() {
        return numePrenume;
    }

    public void setNumePrenume(String numePrenume) {
        this.numePrenume = numePrenume;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getParola() {
        return parola;
    }

    public void setParola(String parola) {
        this.parola = parola;
    }

    public boolean getContActiv() {
        return contActiv;
    }

    public void setContActiv(boolean contActiv) {
        this.contActiv = contActiv;
    }

    public Date getDataAdaugarii() {
        return dataAdaugarii;
    }

    public void setDataAdaugarii(Date dataAdaugarii) {
        this.dataAdaugarii = dataAdaugarii;
    }

    public short getNivelAccesID() {
        return nivelAccesID;
    }

    public void setNivelAccesID(short nivelAccesID) {
        this.nivelAccesID = nivelAccesID;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userID != null ? userID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users) object;
        if ((this.userID == null && other.userID != null) || (this.userID != null && !this.userID.equals(other.userID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "my.servlets.Users[ userID=" + userID + " ]";
    }

}

If I missed to post any other information please tell me and I will put it online.

Please help me.
Manny thanks in advance.

  • 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-14T03:08:11+00:00Added an answer on June 14, 2026 at 3:08 am

    First thing to to in a situation like this is to check the connection to server manually to make sure that you have access to server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my java program I used Hybernate technology to access MySQL database table called
We are starting a new java web-project with Cassandra as the database. The team
My Web application makes use of Ext JS & Java web technology. Due to
i have the problem when i want to try web socket technology on my
For a new application I need to make a decision on what frontend technology
Possible Duplicate: How to internationalize a java web application I'm new in JSP technology
I'm fairly new to Java, and very new to the webstart technology. I've been
Can any one give me detailed information about Java's new technology that is JAXX.
I'm new to Java-based web programming and am trying to learn JSF from the
I am absolutely new in Servlet technology and this is absolutely basic question, but

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.