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

جلب اليوزرنيم والباسوورد من الديتابيس

بدأه smart princess في 17 مارس 2012 · 9 رد · 1,048 مشاهدة · في JavaEE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

اخواني انا عملت مشروع بالجافا وعلى مستخدم المشروع ان يدخل اليوزر نيم والباسوورد علشان يقدر يدخل البرنامج فاستخدمت هذا الكود:

String usr="admin";
        String text="123";
        String wrong="Incorrect Password or username";
        adminMain a=new adminMain();
        if(pword.getText() == null ? text == null : pword.getText().equals(text)&&(user.getText() == null ? usr == null : user.getText().equals(usr))) {
            a.setVisible(true);
            dispose();
        }

        else{
            JOptionPane.showMessageDialog(rootPane, wrong);
        }

وطبعا هذا في حال اني اخترت يوزرنيم وباسورد ثابتات ، لكني اريد ان اجلب اليوزر نيم والباسوورد من الديتا بيس فما هو الكود اللازم لذلك؟

#2

إستخدم JDBC

http://java.sun.com/tutorial/jdbc

#3

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

#4

إستخدم الطريقه التاليه

final String wrong="Incorrect Password or username";

if (isLoggedIn(user.getText(),  pword.getText()) ) 
{
	adminMain a = new adminMain();
    a.setVisible(true);
    dispose();
}else
{
    JOptionPane.showMessageDialog(rootPane, wrong);
}


// 
boolean isLoggedIn(final String userName, final String password)
{
	String sql = "SELECT * FROM USER_TABLE where username = ? and passowrd = ?";
	// set parameters and execute query 
	// ResultSet rs = ....
	return true;	// if found in Database, otherwise return false;
}
1
#5

جزاك الله خير الجزاء اخي وزادك علم

#6
__Unknown كتب:

إستخدم الطريقه التاليه

final String wrong="Incorrect Password or username";

if (isLoggedIn(user.getText(),  pword.getText()) ) 
{
	adminMain a = new adminMain();
    a.setVisible(true);
    dispose();
}else
{
    JOptionPane.showMessageDialog(rootPane, wrong);
}


// 
boolean isLoggedIn(final String userName, final String password)
{
	String sql = "SELECT * FROM USER_TABLE where username = ? and passowrd = ?";
	// set parameters and execute query 
	// ResultSet rs = ....
	return true;	// if found in Database, otherwise return false;
}

اخي طبقت هالكود لكن يعطيني خطأ في مكانين

المكان الاول مع ال isLoggedIn

والمكان الثاني السطر هذا

boolean isLoggedIn(final String userName, final String password){

ويعطيني الخطأ

identifier expected

';' expected

ما الحل؟؟

#7

قومى بإرفاق الكود كاملا ....

#8
import javax.swing.JOptionPane;


public class login extends javax.swing.JFrame {
 public login() {

        initComponents();
    }
 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        String exit="See you later";

        JOptionPane.showMessageDialog(rootPane, exit);

        System.exit(0);
    }                                        

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


        final String wrong="Incorrect Password or username";

if (isLoggedIn(user.getText(),  pword.getText()) ) 
{
        adminMain a = new adminMain();
    a.setVisible(true);
    dispose();
}else
{
    JOptionPane.showMessageDialog(rootPane, wrong);
}


// 
boolean isLoggedIn(final String userName, final String password)
{
        String sql = "SELECT * FROM USER_TABLE where username = ? and passowrd = ?";
        // set parameters and execute query 
        // ResultSet rs = ....
        return true;    // if found in Database, otherwise return false;
}

        /*String usr="admin";
        String text="123";
        String wrong="Incorrect Password or username";
        adminMain a=new adminMain();
        if(pword.getText() == null ? text == null : pword.getText().equals(text)&&(user.getText() == null ? usr == null : user.getText().equals(usr))) {
            a.setSize(816,628);
            a.setVisible(true);
            dispose();
        }

        else{
            JOptionPane.showMessageDialog(rootPane, wrong);
        }*/
    }                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                login lg = new login();
                lg.setSize(816, 535);
                lg.setVisible(true);

            }
        });
    }

تم تعديل هذه المشاركة بواسطة smart princess في 1 أبريل 2012 في 23:33

#9
import javax.swing.JOptionPane;


public class login extends javax.swing.JFrame {
 public login() {

        initComponents();
    }
 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        String exit="See you later";

        JOptionPane.showMessageDialog(rootPane, exit);

        System.exit(0);
    }                                        

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


        final String wrong="Incorrect Password or username";

	if (isLoggedIn(user.getText(),  pword.getText()) ) 
	{
        adminMain a = new adminMain();
    	a.setVisible(true);
    	dispose();
	}else
	{
    	JOptionPane.showMessageDialog(rootPane, wrong);
	}
}		// mhewedy


// 
boolean isLoggedIn(final String userName, final String password)
{
        String sql = "SELECT * FROM USER_TABLE where username = ? and passowrd = ?";
        // set parameters and execute query 
        // ResultSet rs = ....
        return true;    // if found in Database, otherwise return false;
}

        /*String usr="admin";
        String text="123";
        String wrong="Incorrect Password or username";
        adminMain a=new adminMain();
        if(pword.getText() == null ? text == null : pword.getText().equals(text)&&(user.getText() == null ? usr == null : user.getText().equals(usr))) {
            a.setSize(816,628);
            a.setVisible(true);
            dispose();
        }

        else{
            JOptionPane.showMessageDialog(rootPane, wrong);
        }*/                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                login lg = new login();
                lg.setSize(816, 535);
                lg.setVisible(true);

            }
        });
    }
}
1
#10

شكرا لك اخي وجزاك الله خير الجزاء

قد حللت المشكله ^^

تم تعديل هذه المشاركة بواسطة smart princess في 2 أبريل 2012 في 17:56

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