復利計算器6.0


  對界面進行了升級添加了用戶注冊於登錄界面,更完善的功能待續。。。。

主要代碼:

 1 package DataBase;
 2 
 3 import java.sql.Connection;
 4 import java.sql.ResultSet;
 5 import java.sql.SQLException;
 6 import java.sql.Statement;
 7 
 8 public class SingUpConnect {
 9     private Connection connection;
10     private Statement statement;
11     ResultSet resultSet;
12     private String name;
13     private String password;
14     public String getName() {
15         return name;
16     }
17     public void setName(String name) {
18         this.name = name;
19     }
20     public String getPassword() {
21         return password;
22     }
23     public void setPassword(String password) {
24         this.password = password;
25     }
26     public SingUpConnect() {
27         connection=ConnectionFactory.getInstane().makeConnection();
28     }
29     public void Sin_In() {
30         ResultSet resultSet=null;
31         String sql="SELECT * FROM user";
32         try {
33             statement=connection.createStatement();
34         } catch (SQLException e) {
35             
36             e.printStackTrace();
37         }
38         try {
39             resultSet=statement.executeQuery(sql);
40             while (resultSet.next()) {
41                 name=resultSet.getString("name");
42                 password=resultSet.getString("password");
43             }
44         } catch (SQLException e) {
45             
46             e.printStackTrace();
47         }
48         try {
49             while (resultSet.next()) {
50                 System.out.println(resultSet.getString("username"));
51                 System.out.println(resultSet.getString("password"));
52             }
53         } catch (SQLException e) {
54             
55             e.printStackTrace();
56         }
57         finally{
58             try {
59                 resultSet.close();
60             } catch (Exception e2) {
61                 
62             }
63             try {
64                 statement.close();
65             } catch (Exception e2) {
66                 
67             }
68             try {
69                 connection.close();
70             } catch (Exception e2) {
71             
72             }
73         }
74         
75     }
76     public void SinUp(String name,String password){
77         try {
78             connection.setAutoCommit(false);
79             UserDao userDao=new UserDaoImpl();
80             User user=new User();
81             user.setName(name);
82             user.setPassword(password);
83             userDao.save(connection, user);
84             connection.commit();
85         } catch (Exception e) {
86             try {
87                 connection.rollback();
88             } catch (Exception e2) {
89                 e2.printStackTrace();
90             }
91         }
92     }
93 }

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM