~quizsilver/quizsilver/trunk

« back to all changes in this revision

Viewing changes to src/account/AccountFunctions.java

  • Committer: student
  • Author(s): Roxas,Pascual,Amoranto
  • Date: 2009-12-07 07:27:27 UTC
  • Revision ID: student-20091207072727-1vxgxhuiqsmj9hp1
Added Accountfunctions which can be used to query the database

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package account;
 
2
 
 
3
import java.sql.Connection;
 
4
import java.sql.PreparedStatement;
 
5
import java.sql.ResultSet;
 
6
 
 
7
import db.DBConnectionFactory;
 
8
 
 
9
public class AccountFunctions {
 
10
 
 
11
        public Account ViewUsingUsername(String username)
 
12
        {
 
13
                 Account result = new Account();
 
14
                try
 
15
                   {
 
16
                                    
 
17
                                        DBConnectionFactory Factory = DBConnectionFactory.getInstance();
 
18
                            Connection conn = Factory.getConnection();
 
19
                            String sql = "select * from useraccounts where username = ?;";
 
20
                            PreparedStatement pstmt = conn.prepareStatement(sql);
 
21
                            pstmt.setString(1,username);                  
 
22
                            ResultSet rs = pstmt.executeQuery();
 
23
                           
 
24
                            if(rs.next())
 
25
                            {
 
26
                                result.setAcountnum(rs.getInt("accountnumber"));
 
27
                                result.setPassword(rs.getString("pssword"));
 
28
                                result.setUsertype(rs.getString("type"));
 
29
                                result.setUsername(username);
 
30
                            }
 
31
                            System.out.println("Add success");
 
32
                   }
 
33
                   catch(Exception e)
 
34
                   {
 
35
                           e.printStackTrace();
 
36
                   }
 
37
                return result;  
 
38
        }
 
39
        
 
40
}