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

ساعدوني في عملية الربط بالأوراكل ...

مغلق
بدأه limo في 18 أبريل 2003 · 4 رد · 738 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

[ALIGN=RIGHT]اخواني الكرام ....

اخوكم مبتدأ في الجافا .. يطلب المساعدة منكم ...

قمت بالربط بالوراكل مع الجافا واظهرت البيانات في Textfields استخدمت button

في عملية التنقل بين البيانات ...

قد نجحت في عملية الإنتقال ل record التالي .. ولكن كيف يمكن العودة

ل record السابق ؟؟؟

import java.sql.*;
public class Oracle extends Frame implements ActionListener {
    TextField t1,t2;
    Button b1,b2,b3;
    Label l1,l2;
    FlowLayout f;
    Color c,cb;
    Connection connection;
    Statement statement;
    ResultSet result;
    public Oracle() {
    c = new Color(255,215,255);
    f = new FlowLayout();
    setLayout(f);
    l1 = new Label("EmpNumber");
    l1.setForeground©;
    t1 = new TextField(3);
    l2 = new Label("EmpName");
    l2.setForeground©;
    t2 = new TextField(8);
    b1 = new Button("Next");
    b1.addActionListener(this);
    b2 = new Button("Exit");
    b2.addActionListener(this);
    b3 = new Button("Back");
    b3.addActionListener(this);
    cb = new Color(0,0,0);
    setBackground(cb);
    add(l1);add(t1);add(l2);add(t2);add(b1);add(b2);add(b3);
    // Oracle Connection .. 
          try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }
        catch(Exception e){}
        try{
            connection = DriverManager.getConnection("jdbc:odbc:ORC_Library","scott","tiger");
            statement  = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
            result  = statement.executeQuery("select * from emp");
        }
        catch(SQLException e){
            System.out.println(e.toString());
        }
    }
    public void actionPerformed(ActionEvent e)
    {
        if(e.getActionCommand()=="Exit")
        System.exit(0);
        if(e.getActionCommand()=="Next")
        try{
        result.next();
        t1.setText(result.getString("empno"));
        t2.setText(result.getString("ename"));
       if(result.next()==false){
       result.close();
       statement.close();
            connection.close();
         }

            }
        catch(SQLException f)
            {
                System.out.println(f.toString());
            }
         if(e.getActionCommand()=="Back") {
            try
            {
            result.deleteRow();
            }
            catch(SQLException q)
            {
                System.out.print(q.toString());
            }
        }

      }


    public static void main(String args[])
    {
        Oracle obj =new Oracle();
        obj.setSize(400,100);
        obj.show();
    }
}
#2

بالاوراكل لكل صف له رقم معين يعني 1 2 3 4 الخ..

فانت يوم تطلب صف معين من المعلومات و تبغى الصف اللي قبله .. تطلب منه انه يعطيك المعلومات بالصف السابق .. انا نسيت الطريقه لكن انا سويت حيله و هي تسمي عمود باسم ID .. و ترقمه بالترقيم 1 2 3 .. عشان اذا تبغى معلومات بصف معين .. تقدر تطلب هذا الصف برقمه الـ ID ..

;)

#3

في البداية جزاك الله الف خير اخي صلاح ...

بالنسبة لحلك فقد فكرت مسبقا به .. ولكن ابحث عن حل آخر باستخدام

previous() method , مع العلم أن في الحالة العادية the cursor of resultSet

يتحرك من البداية إلى النهاية فقط .. فكيف مكن ان نتحكم في تحركه ؟؟؟

#4

الحقيقه ما شفت الـ methods الموجوده بالمستندات :( ..

يمكن في واحد شافها و يقدر يساعدك :)

#5

أخي صلاح .. الشكر الجزيل لمجهودك وتفعالك معي ...

ولله الحمد وجدت الحل .. وهذا الكود جاهز يعمل 100% إن شاء الله

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

public class Oracle extends Frame implements ActionListener {

    TextField t1,t2;

    Button b1,b2,b3;

    Label l1,l2;

    FlowLayout f;

    Color c,cb;

    Connection connection;

    Statement statement;

    ResultSet result;

    public Oracle() {

    c = new Color(255,215,255);

    f = new FlowLayout();

    setLayout(f);

    l1 = new Label("EmpNumber");

    l1.setForeground(c);

    t1 = new TextField(3);

    l2 = new Label("EmpName");

    l2.setForeground(c);

    t2 = new TextField(8);

    b1 = new Button("Next");

    b1.addActionListener(this);

    b2 = new Button("Exit");

    b2.addActionListener(this);

    b3 = new Button("Back");

    b3.addActionListener(this);

    cb = new Color(0,0,0);

    setBackground(cb);

    add(l1);add(t1);add(l2);add(t2);add(b1);add(b2);add(b3);

    // Oracle Connection .. 

          try{

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

        }

        catch(Exception e){}

        try{

            connection = DriverManager.getConnection("jdbc:odbc:ORC_Library","scott","tiger");

            statement  = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

                                      ResultSet.CONCUR_UPDATABLE);

            result  = statement.executeQuery("select * from emp");

        }

        catch(SQLException e){

            System.out.println(e.toString());

        }

    }

    public void nextR()

    {

                try{

        result.next();

        t1.setText(result.getString("empno"));

        t2.setText(result.getString("ename"));

       if(result.next()==false){

       result.close();

       statement.close();

            connection.close();

         }

        

            }

        catch(SQLException f)

            {

                System.out.println(f.toString());

            }

    }

    

    public static void main(String args[])

    {

        Oracle obj =new Oracle();

        obj.setSize(400,100);

        obj.show();

    }

    public void windowClosing(final java.awt.event.WindowEvent p1) {

        System.exit(0);

    }

     public void actionPerformed(final java.awt.event.ActionEvent e)

    {

        if(e.getActionCommand()=="Exit")

        System.exit(0);

        if(e.getActionCommand()=="Next")

            nextR();

         if(e.getActionCommand()=="Back") {

            try

            {

            result.previous(); 

            t1.setText(result.getString("empno"));

            t2.setText(result.getString("ename"));

            }

            catch(SQLException q)

            {

                System.out.print(q.toString());

            }

        }

     

      }

}

هذا الموضوع مغلق.

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