我在Neatbeans中有一个登录和一个系统表单。当用户登录系统时,他应该只看到有关他的数据。用户表列为(id, name, surname, is_vip, startdate, enddate)
我的登录表单代码uye_ka(username)
uye_sifre(password)
我可以从MySQL表中获取数据,但我不知道如何只显示该成员的数据
conn = Baglan.DBBaglan();
String SQL = "SELECT * FROM uyeler2 where uye_ka=? and uye_sifre=?";
try {
ps = conn.prepareStatement(SQL);
ps.setString(1, uye_ka.getText());
ps.setString(2, uye_sifre.getText());
rs = ps.executeQuery();
if (rs.next()) {
JOptionPane.showMessageDialog(null, "Sisteme hoşgeldiniz.");
Sistem sis = new Sistem();
sis.setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "Geçersiz kullanıcı adı veya şifre.", "Erişiminiz engellendi.", JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
当用户成功登录到包含数据表的系统系统表单时,我想显示属于登录用户的数据
DefaultTableModel model=(DefaultTableModel) tablo.getModel();
Connection conn=null;
try
{
conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/uyelerdb", "root","123456");
String SQL="SELECT * FROM uyeler2";
Statement durum=(Statement) conn.createStatement();
ResultSet rs=(ResultSet) durum.executeQuery(SQL);
while(rs.next())
{
model.addRow(new Object[]{rs.getString("id"),rs.getString("adi"),rs.getString("soyadi")
,rs.getString("vip_mi"),rs.getString("baslangıc"),rs.getString("bitis")});
}
}
catch(SQLException e)
{
System.err.println("SQL Exception: "+e.getMessage());
System.exit(1);
}
我获取所有用户数据ı只需要一个用户的数据