الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ايريد ان اعرف كيفية اظهار نتيجة استعلام في textfield باستعمال Hebernate

بدأه eloued39004 في 2 أغسطس 2011 · 6 رد · 581 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

السلام عليكم و رحمة الله و بركاته

ايريد ان اعرف كيفية اظهار نتيجة استعلام في textfield باستعمال Hebernate و كذلك كيفية الحذف و التعديل و الاضافة في قاعدة بيانات

و ان امكن ارفاق مثال بسيط للتوضيح

مع العلم اني حاولة التعلم من هذا المثال

http://netbeans.org/kb/docs/java/hibernate-java-se.html

لكن لم انجح فارجوا المساعدة بارك الله فيكم اخواني و تقبل صيامكم و قيامكم

#2

كيفيه اظهار نتيجه الاستعلام

هذا امر ليس له علاقه بالـ Hibernate

فانت تقوم باستعاده نتيجه الاستعلام

وبعدها تضعها فى TextField باستخدام الداله setText

كيفيه الحذف والاضافه والتعديل

يكون ذلك عبر استخدام الـ Session Object

للحذف

session.delete(object);

للتعديل

session.update(object);

للاضافه

session.save(object);

وبعدها تستخدم commit

session.getTransaction().commit();

لتنفيذ العملية

Software Developer
Mahmoudkelany.com


 

#3

بارك الله فيك اخي

اخي اين الخطأ هنا

package islam.prayer.times.show;

import java.util.*;

import org.hibernate.HibernateException;

import org.hibernate.Query;

import org.hibernate.Session;

import islam.prayer.times.util.HibernateUtil;

import islam.prayer.times.entity.Time;

/**

*

* @author guenoua

*/

public class pray extends javax.swing.JFrame {

/** Creates new form pray */

public pray() {

initComponents();

}

public static String query = "from Time";

private void runquery(){

executeHQLQuery(query);

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

t1 = new javax.swing.JTextField();

t2 = new javax.swing.JTextField();

t3 = new javax.swing.JTextField();

t4 = new javax.swing.JTextField();

t5 = new javax.swing.JTextField();

t6 = new javax.swing.JTextField();

b1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

t1.setText("jTextField1");

t2.setText("jTextField2");

t3.setText("jTextField3");

t4.setText("jTextField4");

t5.setText("jTextField5");

t6.setText("jTextField6");

b1.setText("Show");

b1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

b1ActionPerformed(evt);

}

});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(69, 69, 69)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(t5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(99, 99, 99)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(b1)

.addComponent(t6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))

.addContainerGap(114, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(31, 31, 31)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addGroup(layout.createSequentialGroup()

.addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(30, 30, 30)

.addComponent(t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(38, 38, 38))

.addGroup(layout.createSequentialGroup()

.addComponent(b1)

.addGap(18, 18, 18)))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(t3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(t6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(36, 36, 36)

.addComponent(t4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)

.addComponent(t5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(32, 32, 32))

);

pack();

}// </editor-fold>

private void b1ActionPerformed(java.awt.event.ActionEvent evt) {

runquery();

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new pray().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JButton b1;

private javax.swing.JTextField t1;

private javax.swing.JTextField t2;

private javax.swing.JTextField t3;

private javax.swing.JTextField t4;

private javax.swing.JTextField t5;

private javax.swing.JTextField t6;

// End of variables declaration

private void executeHQLQuery(String hql){

try{

Session session = HibernateUtil.getSessionFactory().openSession();

session.beginTransaction();

Query q = session.createQuery(hql);

List resultList = q.list();

displayResult(resultList);

session.getTransaction().commit();

}catch(HibernateException he){

he.printStackTrace();

}

}

private void displayResult(List resultList){

Time time = new Time();

t1.setText(time.getDatep().toString());

t2.setText(time.getPf().toString());

t3.setText(time.getPd().toString());

t4.setText(time.getPa().toString());

t5.setText(time.getPm().toString());

t6.setText(time.getPi().toString());

}

}

#4

انا مش عارف ايه المكتبه اللى انت مستخدمها فى كدا

import islam.prayer.times.util.HibernateUtil;
import islam.prayer.times.entity.Time;

ملهاش لازمه دى

session.getTransaction().commit();

هو الـ Query دا

Query q = session.createQuery(hql);
List resultList = q.list();

انت كدا عامله انه يعمل اختيار لجميع صفوف الجدول Time

وبعدين الداله

  private void displayResult(List resultList) {
    	Time time = new Time();
    	t1.setText(time.getDatep().toString());
    	t2.setText(time.getPf().toString());
    	t3.setText(time.getPd().toString());
    	t4.setText(time.getPa().toString());
    	t5.setText(time.getPm().toString());
    	t6.setText(time.getPi().toString());

	}

انت كدا مش استخدمت الـ list اللى حصلت عليها من الـ Query

وعملت كائن جديد وبدأت تاخد منه البيانات

راجع تصميم كودك بتأنى ودقة

Software Developer
Mahmoudkelany.com


 

#5

بارك الله فيك اخي

تم حل المشكل

لكن تواجهني مشكل آخر حين احاول عمل build لانشاء ملف الجار تاتيني هذه الرسالة

unmappable character for encoding UTF-8

unmappable character for encoding UTF-8

// Generated 2 ao?t 2011 19:23:15 by Hibernate Tools 3.2.1.GA

The following error occurred while executing this line:

Compile failed; see the compiler error output for details.

BUILD FAILED (total time: 1 second)

#6
eloued39004 كتب:

بارك الله فيك اخي

تم حل المشكل

لكن تواجهني مشكل آخر حين احاول عمل build لانشاء ملف الجار تاتيني هذه الرسالة

unmappable character for encoding UTF-8

unmappable character for encoding UTF-8

// Generated 2 ao?t 2011 19:23:15 by Hibernate Tools 3.2.1.GA

The following error occurred while executing this line:

Compile failed; see the compiler error output for details.

BUILD FAILED (total time: 1 second)

بصراحه المشكله غير واضحه

اعمل Clean وبعدين اعمل Build وان شاء الله ممكن تشتغل معاك

Software Developer
Mahmoudkelany.com


 

#7

بارك الله فيك اخي تم حل المشكل

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…