2017-03-25 18 views
0

私は大学での初心者です。システムを開発する必要があります。ログインフォームのシステムには、ユーザー名、パスワード、jcomboboxを使用してユーザーレベルを選択する3つのフィールドがあります。私のプロジェクトでやった限りでは、私は任意のユーザ名、データベースのパスワードでログインすることができ、私はデータベースにjcomboboxをリンクしています。しかし、データベースに保存されている特定のユーザ名とパスワードを与えてログインしたいjcomboboxから特定のログインレベル(管理者/マネージャ/エンジニアのログインなど)を選択します。その特定の人は、ユーザー名、パスワード、レベルでログインできます。別のレベルの他の人は、必要なユーザー名、パスワード、レベルを指定する必要があります。 は、ここで私は多くのことを試してみたが、私は私の希望result.Will誰が?ありがとうございました:で私を助けてもらうために行う必要が正確に何を把握することはできませんJava Netbeansログインフォーム

import java.awt.Toolkit; 
import java.awt.event.KeyEvent; 
import java.awt.event.WindowEvent; 
import java.sql.*; 
import javax.swing.*; 

public class LogInJFrame extends javax.swing.JFrame { 

Connection conn=null; 
ResultSet rs = null; 
PreparedStatement pst=null; 

public LogInJFrame() { 
    initComponents(); 
    conn=JavaConnector.ConnectorDb(); 
    Fill_Combo(); 
} 

private void Fill_Combo() 
{ 
    try 
    { 
     String sql="Select * from Level"; 
     pst=conn.prepareStatement(sql); 
     rs=pst.executeQuery(); 
     while(rs.next()){ 
     String type=rs.getString("Type"); 
     cmb_loginAs.addItem(type); 
     } 
    } 
    catch(Exception e) 
    { 
     JOptionPane.showMessageDialog(null, e); 
    } 
    finally 
    { 
     try 
     { 
      rs.close(); 
      pst.close(); 

     } 
     catch(Exception e) 
     { 

     } 
    } 
} 

private void btn_loginActionPerformed(java.awt.event.ActionEvent evt) {           
    String sql="select * from Level where UserName =? and Password =? "; 
try{ 

pst =conn.prepareStatement(sql); 
pst.setString(1, txt_username.getText()); 
pst.setString(2, txt_password.getText()); 

rs=pst.executeQuery(); 

if(rs.next()) 
{ 
    JOptionPane.showMessageDialog(null, "The Username and Password is correct"); 
    rs.close(); 
    pst.close(); 

    AdministratorLogin ad=new AdministratorLogin(); 
    ad.setVisible(true); 
} 
else 
{ 
    JOptionPane.showMessageDialog(null, "The Username and Password is not correct"); 
} 
} 
catch(Exception e) 
{ 
JOptionPane.showMessageDialog(null, e); 
} 
finally 
    { 
     try 
     { 
      rs.close(); 
      pst.close(); 

     } 
     catch(Exception e) 
     { 

     } 
    } 
}           

private void txt_passwordKeyPressed(java.awt.event.KeyEvent evt) {           
    if(evt.getKeyCode()==KeyEvent.VK_ENTER) 
    { 
     String sql="select * from Level where UserName =? and Password =? "; 
try{ 

pst =conn.prepareStatement(sql); 
pst.setString(1, txt_username.getText()); 
pst.setString(2, txt_password.getText()); 

rs=pst.executeQuery(); 
if(rs.next()) 
{ 
    JOptionPane.showMessageDialog(null, "The Username and Password is correct"); 
    rs.close(); 
    pst.close(); 

    AdministratorLogin ad=new AdministratorLogin(); 
    ad.setVisible(true); 
} 
else 
{ 
    JOptionPane.showMessageDialog(null, "The Username and Password is not correct"); 
} 
} 
catch(Exception e) 
{ 
JOptionPane.showMessageDialog(null, e); 
} 
finally 
    { 
     try 
     { 
      rs.close(); 
      pst.close(); 

     } 
     catch(Exception e) 
     { 

     } 
    } 

    } 
}               
} 

、私のコードです。

答えて

0

ユーザー名とパスワードは、常にDB内部のアカウントタイプにリンクできます。それからそれをDBストアから取り出して文字列にします。次に何かをする

if(accountType.equals("engineer")) { 
    // load specific page 
} 
関連する問題