码迷,mamicode.com
首页 > 其他好文 > 详细

复利计算器6.0

时间:2016-04-14 23:58:38      阅读:501      评论:0      收藏: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 }

 

技术分享技术分享技术分享

 

复利计算器6.0

标签:

原文地址:http://www.cnblogs.com/LwF39/p/5393377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!