Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i have a database table called \"COMMUNIK\", and this is how i created CREATE TA

ID: 3864305 • Letter: I

Question

i have a database table called "COMMUNIK", and this is how i created

CREATE TABLE `COMMUNIK` (
`PID` int(11) NOT NULL AUTO_INCREMENT,
`KID` char(3) DEFAULT NULL,
`CID` char(6) DEFAULT NULL,
`COMMUNIK` longtext,
`ACTIVE` enum('T','F') DEFAULT 'T',
`FALLBACK` char(3) DEFAULT NULL,
`IP` char(15) DEFAULT NULL,
`USERNAME` varchar(25) DEFAULT NULL,
`TSTAMP` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`PID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

now i have Communik.java and CommunikDAO.java

what i need is it has to read data from the database table and store in the form of arrays.

can u please write Communik.java and CommunikDAO.java please?

Explanation / Answer

---------------------------------------------------Communik.java--------------------------------------------------------------------

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="communik")
public class Communik {
  
   @Column(name="PID")
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   private int pid;
  
   @Column(name="KID",columnDefinition="CHAR(3)")
   private String kid;
  
   @Column(name="CID",columnDefinition="CHAR(6)")
   private String cid;
  
   @Column(name="COMMUNIK",columnDefinition="LONGTEXT")
   private String communik;
  
   @Column(name="ACTIVE", columnDefinition="enum('T','F')")
   public String active;
  
   @Column(name="FALLBACK",columnDefinition="CHAR(3)")
   public String fallBack;
  
   @Column(name="IP",columnDefinition="CHAR(15)")
   public String ip;
  
   @Column(name="USERNAME",columnDefinition="CHAR(25)")
   public String userName;
  
  
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "TSTAMP",columnDefinition="TIMESTAMP default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP")
   private Date timeStamp = new Date();


   /**
   * @return the pid
   */
   public synchronized int getPid() {
       return pid;
   }


   /**
   * @param pid the pid to set
   */
   public synchronized void setPid(int pid) {
       this.pid = pid;
   }


   /**
   * @return the kid
   */
   public synchronized String getKid() {
       return kid;
   }


   /**
   * @param kid the kid to set
   */
   public synchronized void setKid(String kid) {
       this.kid = kid;
   }


   /**
   * @return the cid
   */
   public synchronized String getCid() {
       return cid;
   }


   /**
   * @param cid the cid to set
   */
   public synchronized void setCid(String cid) {
       this.cid = cid;
   }


   /**
   * @return the communik
   */
   public synchronized String getCommunik() {
       return communik;
   }


   /**
   * @param communik the communik to set
   */
   public synchronized void setCommunik(String communik) {
       this.communik = communik;
   }


   /**
   * @return the active
   */
   public synchronized String getActive() {
       return active;
   }


   /**
   * @param active the active to set
   */
   public synchronized void setActive(String active) {
       this.active = active;
   }


   /**
   * @return the fallBack
   */
   public synchronized String getFallBack() {
       return fallBack;
   }


   /**
   * @param fallBack the fallBack to set
   */
   public synchronized void setFallBack(String fallBack) {
       this.fallBack = fallBack;
   }


   /**
   * @return the ip
   */
   public synchronized String getIp() {
       return ip;
   }


   /**
   * @param ip the ip to set
   */
   public synchronized void setIp(String ip) {
       this.ip = ip;
   }


   /**
   * @return the userName
   */
   public synchronized String getUserName() {
       return userName;
   }


   /**
   * @param userName the userName to set
   */
   public synchronized void setUserName(String userName) {
       this.userName = userName;
   }


   /**
   * @return the timeStamp
   */
   public synchronized Date getTimeStamp() {
       return timeStamp;
   }


   /**
   * @param timeStamp the timeStamp to set
   */
   public synchronized void setTimeStamp(Date timeStamp) {
       this.timeStamp = timeStamp;
   }

}

-------------------------------------------------------------------------CommunikDao.java------------------------------------------------------

/**
*
*/

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.essentials.model.Communik;

/**
* @author JKishore
*
*/
public class CommunikDao {
   @Autowired
private SessionFactory sessionFactory;
  
   //get the current session
   protected Session getSession() {
   return sessionFactory.getCurrentSession();
   }
  
   /**
   *   
   * @return array of communik
   */
   Communik[] getAll(){
       String query = "from Communik";
       Query hqlQuery = getSession().createQuery(query);
       List<Communik> communikList = hqlQuery.list();
       return (Communik[])communikList.toArray();
   }
}