-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerBo.java
More file actions
80 lines (75 loc) · 2.28 KB
/
Copy pathPlayerBo.java
File metadata and controls
80 lines (75 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.mphasis.demo.bo;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.mphasis.demo.connection.MyConnection;
import com.mphasis.demo.model.Player;
public class PlayerBo
{
public boolean insertPlayer(Player p) throws Exception
{
Connection con = MyConnection.getConnection();
PreparedStatement ps = con.prepareStatement("insert into player175 values(?,?,?,?,?)");
ps.setInt(1, p.getPlayerNumber());
ps.setInt(2, p.getTeamNo());
ps.setString(3, p.getPlayerName());
ps.setInt(4,p.getNoOfMatches());
ps.setString(5, p.getSkill());
boolean a = ps.execute();
return a;
}
public Player getPlayer(int id)throws Exception
{
Player p = null;
Connection con = MyConnection.getConnection();
PreparedStatement ps = con.prepareStatement("select * from player175 where pno=?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
while(rs.next())
{
p = new Player(id,rs.getInt(2),rs.getString(3), rs.getInt(4), rs.getString(5));
}
return p;
}
public boolean updatePlayer(Player p) throws Exception
{
Connection con = MyConnection.getConnection();
PreparedStatement ps = con.prepareStatement("update player175 set tno=?,playername=?, nofmatches=?,skill=? where pno=?");
ps.setInt(1, p.getTeamNo());
ps.setString(2, p.getPlayerName());
ps.setInt(3, p.getNoOfMatches());
ps.setString(4, p.getSkill());
ps.setInt(5, p.getPlayerNumber());
boolean a = ps.execute();
con.commit();
con.close();
return a;
}
public boolean deletePlayer(Player p) throws Exception
{
Connection con = MyConnection.getConnection();
String a = "delete from player175 where pno=?";
PreparedStatement ps = con.prepareStatement(a);
ps.setInt(1, p.getPlayerNumber());
ps.executeUpdate();
con.close();
return true;
}
public List<Player> getAllPlayers() throws Exception
{
List<Player> al = new ArrayList<Player>();
Connection con = MyConnection.getConnection();
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("select * from player175");
while(rs.next())
{
al.add(new Player(rs.getInt(1), rs.getInt(2), rs.getString(3), rs.getInt(4), rs.getString(5)));
System.out.println();
}
con.close();
return al;
}
}