程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-如何修改下面的java程序,我希望當點擊登陸按鈕時候,能夠跳轉到聊天界面。我已經鏈接了數據庫了

android-如何修改下面的java程序,我希望當點擊登陸按鈕時候,能夠跳轉到聊天界面。我已經鏈接了數據庫了

編輯:編程綜合問答
如何修改下面的java程序,我希望當點擊登陸按鈕時候,能夠跳轉到聊天界面。我已經鏈接了數據庫了

我的要求如下,在文本框輸入賬號和密碼,連接數據庫驗證碼賬號和密碼是否一致,如果一致就當點擊登陸按鈕時候就跳轉到聊天界面。麻煩你幫我修改一下程序,
package sql;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

import javax.swing.*;
class liaotian extends JFrame implements ActionListener{
JPanel jpanel1;
TextArea textArea1;
TextField textField3;
JButton jButton1;
liaotian(){
this.setTitle("對話");
this.setSize(600,600);
this.setVisible(true);
jpanel1=new JPanel();
textArea1=new TextArea(15,15);
jButton1=new JButton("發送");
textField3=new TextField(10);
jpanel1.add(textArea1);
jButton1.addActionListener(this);
jpanel1.add(jButton1);jpanel1.add(textField3);
this.add(jpanel1);

}
public void actionPerformed(ActionEvent e) {
     if(e.getSource()==jButton1){
         textArea1.setText(textField3.getText());
         textField3.setText("");
     }}}

public class lianxi2 extends JFrame implements ActionListener{
JPanel jpanel;
Label label1;
TextField textField1;
Label label2;
TextField textField2;
JButton jButton;
static String col11,col12;
public lianxi2(){
super("登陸");
jpanel=new JPanel();
this.setVisible(true);
this.setSize(600,600);
label1=new Label("賬號");
textField1=new TextField(15);
label2=new Label("密碼");
textField2=new TextField(15);
jButton=new JButton("登陸");

jpanel.add(label1); jpanel.add(textField1);
jpanel.add(label2); jpanel.add(textField2);
jpanel.add(jButton);
this.add(jpanel);
jButton.addActionListener(this); //給jbutton加上監聽

        }
public static void main(String[] args) {
    lianxi2 lt = new lianxi2();
    try{
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//加載數據庫驅動
        Connection conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;Database=denglu","sa","123456");//鏈接數據庫
        Statement statement=conn.createStatement();

        ResultSet rs = statement.executeQuery("select * from denglu ");
        while(rs.next()){
                 col11= rs.getString("zhanghao");
                 col12 = rs.getString("mima");   
               }
        conn.close();
        }

catch(Exception e){
e.printStackTrace();
}
}

public void actionPerformed(ActionEvent e) {
if(e.getSource()==jButton){
if(textField1.getText()==col11){
if(textField2.getText()==col12){
liaotian m=new liaotian();
m.setVisible(true);
}
}
}

}}

最佳回答:


你這樣是取出所有的賬戶

應該是
statement.setstring(1,用戶輸入的用戶名);
statement.setstring(2,用戶輸入的密碼);
ResultSet rs = statement.executeQuery("select * from denglu where zhanghao=? and mima=?");
if (rs.next())
驗證成功

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved