Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Connecting netbeans with sql database

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Connecting netbeans with sql database

    I've connected my database to netbeans and it automatically generated some code for me. This is one of the files of code it created.
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package stud_info;
     
    import java.io.Serializable;
    import java.util.Collection;
    import javax.persistence.Basic;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlTransient;
     
    /**
     *
     * @author vianna
     */
    @Entity
    @Table(name = "student")
    @XmlRootElement
    @NamedQueries({
        @NamedQuery(name = "Student.findAll", query = "SELECT s FROM Student s"),
        @NamedQuery(name = "Student.findByStudId", query = "SELECT s FROM Student s WHERE s.studId = :studId"),
        @NamedQuery(name = "Student.findByLastName", query = "SELECT s FROM Student s WHERE s.lastName = :lastName"),
        @NamedQuery(name = "Student.findByFirstName", query = "SELECT s FROM Student s WHERE s.firstName = :firstName"),
        @NamedQuery(name = "Student.findByGender", query = "SELECT s FROM Student s WHERE s.gender = :gender")})
    public class Student implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @Basic(optional = false)
        @Column(name = "Stud_Id")
        private Integer studId;
        @Basic(optional = false)
        @Column(name = "LastName")
        private String lastName;
        @Basic(optional = false)
        @Column(name = "FirstName")
        private String firstName;
        @Basic(optional = false)
        @Column(name = "Gender")
        private String gender;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "studId")
        private Collection<Address> addressCollection;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "studId")
        private Collection<AcademicDetails> academicDetailsCollection;
     
        public Student() {
        }
     
        public Student(Integer studId) {
            this.studId = studId;
        }
     
        public Student(Integer studId, String lastName, String firstName, String gender) {
            this.studId = studId;
            this.lastName = lastName;
            this.firstName = firstName;
            this.gender = gender;
        }
     
        public Integer getStudId() {
            return studId;
        }
     
        public void setStudId(Integer studId) {
            this.studId = studId;
        }
     
        public String getLastName() {
            return lastName;
        }
     
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
     
        public String getFirstName() {
            return firstName;
        }
     
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
     
        public String getGender() {
            return gender;
        }
     
        public void setGender(String gender) {
            this.gender = gender;
        }
     
        @XmlTransient
        public Collection<Address> getAddressCollection() {
            return addressCollection;
        }
     
        public void setAddressCollection(Collection<Address> addressCollection) {
            this.addressCollection = addressCollection;
        }
     
        @XmlTransient
        public Collection<AcademicDetails> getAcademicDetailsCollection() {
            return academicDetailsCollection;
        }
     
        public void setAcademicDetailsCollection(Collection<AcademicDetails> academicDetailsCollection) {
            this.academicDetailsCollection = academicDetailsCollection;
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (studId != null ? studId.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 Student)) {
                return false;
            }
            Student other = (Student) object;
            if ((this.studId == null && other.studId != null) || (this.studId != null && !this.studId.equals(other.studId))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "stud_info.Student[ studId=" + studId + " ]";
        }
     
    }

    I want to use the database information to make array objects but I dont know where to go from there so that i can assign variables or even get the results of some of the functions in the automated code. Can someone please explain how I go about doing this please?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,110
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: Connecting netbeans with sql database

    Also posted at Connecting netbeans with sql database - Dev Shed
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Connecting Java to SQL
    By moskiongo in forum JDBC & Databases
    Replies: 3
    Last Post: September 10th, 2012, 11:29 AM
  2. Replies: 1
    Last Post: April 19th, 2012, 08:24 AM
  3. Replies: 1
    Last Post: December 15th, 2011, 08:29 AM
  4. Replies: 1
    Last Post: June 14th, 2011, 11:08 AM
  5. Connecting to a database
    By fwashington in forum JDBC & Databases
    Replies: 5
    Last Post: March 15th, 2010, 01:37 PM