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

كيف استعمل ResultSet

بدأه Game111 في 1 يونيو 2011 · 0 رد · 258 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1

السلام عليكم

هذا الكود يظهر فيه خطأ

 public class NewClass1 {
    public static void main(String[]arg) throws SQLException
    {
        ResultSet re = database.excuteQuery("select * from app.login");;
        re.next();
      re=database.excuteQuery("select * from app.login");
        String s=re.getString("password");
        System.out.println(s);
    }

}

و هذا الكلاس الموجود فيه دالة exuteQuerey

 import java.sql.*;
import javax.swing.JOptionPane;

/**
 *
 * @author Asif Khan
 */
public class myDbConnection {

        static final String JDBC_DRIVER = "org.apache.derby.jdbc.ClientDriver";
        static final String DATABASE_URL = "jdbc:derby://localhost:1527/Journal"; 
        static  Connection connection;
        static Statement statement;
        static ResultSet resultSet ;


    public  myDbConnection(){
             try {
                    Class.forName( JDBC_DRIVER );
                     connection = DriverManager.getConnection( DATABASE_URL );
                     statement = connection.createStatement();     
             } catch ( SQLException sqlException ) {
                     JOptionPane.showMessageDialog( null, sqlException.getMessage(), 
                   "Database Error", JOptionPane.ERROR_MESSAGE );
      }

      catch ( ClassNotFoundException classNotFound ) {
                 JOptionPane.showMessageDialog( null, classNotFound.getMessage(), 
                    "Driver Not Found", JOptionPane.ERROR_MESSAGE );            
      }

    }

    public static  ResultSet excuteQuery(String query){
             try {
                      resultSet =   statement.executeQuery(query);

              } catch ( SQLException sqlException ) {
                 JOptionPane.showMessageDialog( null, sqlException.getMessage(), 
                    "Database Error", JOptionPane.ERROR_MESSAGE );
              }
                 return resultSet ;
    }

     public static void excuteUpdate(String query){
          try {
              statement.executeUpdate(query);
      } catch ( SQLException sqlException ) {
             JOptionPane.showMessageDialog( null, sqlException.getMessage(), 
                "Database Error", JOptionPane.ERROR_MESSAGE );
      } 


    }
}

تم تعديل هذه المشاركة بواسطة Game111 في 1 يونيو 2011 في 20:31

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