In this example we select data from database and add these data into a arraylist and return that list.
The page in which you want to use these data simply call this method and cast into required class type. This Example In Java Swing.
Step-1
public List<Personal_CoachingGS> selectAllInvoice(String Query) {
List<Personal_CoachingGS> memberdata = new ArrayList<Personal_CoachingGS>();
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
connection = ConnectionConfiguration.getConnection();
statement = connection.createStatement();
resultSet = statement.executeQuery("SELECT a.m_id,a.m_name,a.m_total_amt,b.Game_Name,c.RC_ID,c.RC_Discount,c.RC_Tax,c.RC_TotalAmount,c.RC_AddedDate FROM pc_receipt c LEFT OUTER JOIN p_member_reg a ON c.RC_Stu_ID=a.m_id"
+" LEFT OUTER JOIN gameregistration b ON a.m_game=b.Game_ID where a.m_com_id='"+Query+"' ORDER BY a.Sno DESC");
while (resultSet.next()) {
Personal_CoachingGS pc = new Personal_CoachingGS();
pc.setM_id(resultSet.getString("m_id"));
pc.setM_name(resultSet.getString("m_name"));
pc.setM_game(resultSet.getString("Game_Name"));
pc.setM_email(resultSet.getString("RC_ID"));
pc.setM_game_sdate(resultSet.getString("RC_Discount"));
pc.setM_game_edate(resultSet.getString("RC_Tax"));
pc.setM_country(resultSet.getString("RC_TotalAmount"));
pc.setM_state(resultSet.getString("RC_AddedDate"));
pc.setM_total_amt(resultSet.getString("m_total_amt"));
memberdata.add(pc);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return memberdata;
}
Step-2
DefaultTableModel model;
model=(DefaultTableModel)jTable1.getModel();
jTable1.setAutoCreateRowSorter(true);
PC_ReciptDB pcdb=new PC_ReciptDB();
List<Personal_CoachingGS> pcgs=pcdb.selectAllInvoice(cid);
for(Personal_CoachingGS data : pcgs)
{
model.insertRow(model.getRowCount(), new Object[]{data.getM_id(),data.getM_name(),data.getM_email(),data.getM_game(),df.format(Double.parseDouble(data.getM_total_amt())),data.getM_game_sdate(),data.getM_game_edate(),df.format(Double.parseDouble(data.getM_country())),data.getM_state()});
}model.fireTableDataChanged();
The page in which you want to use these data simply call this method and cast into required class type. This Example In Java Swing.
Step-1
public List<Personal_CoachingGS> selectAllInvoice(String Query) {
List<Personal_CoachingGS> memberdata = new ArrayList<Personal_CoachingGS>();
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
connection = ConnectionConfiguration.getConnection();
statement = connection.createStatement();
resultSet = statement.executeQuery("SELECT a.m_id,a.m_name,a.m_total_amt,b.Game_Name,c.RC_ID,c.RC_Discount,c.RC_Tax,c.RC_TotalAmount,c.RC_AddedDate FROM pc_receipt c LEFT OUTER JOIN p_member_reg a ON c.RC_Stu_ID=a.m_id"
+" LEFT OUTER JOIN gameregistration b ON a.m_game=b.Game_ID where a.m_com_id='"+Query+"' ORDER BY a.Sno DESC");
while (resultSet.next()) {
Personal_CoachingGS pc = new Personal_CoachingGS();
pc.setM_id(resultSet.getString("m_id"));
pc.setM_name(resultSet.getString("m_name"));
pc.setM_game(resultSet.getString("Game_Name"));
pc.setM_email(resultSet.getString("RC_ID"));
pc.setM_game_sdate(resultSet.getString("RC_Discount"));
pc.setM_game_edate(resultSet.getString("RC_Tax"));
pc.setM_country(resultSet.getString("RC_TotalAmount"));
pc.setM_state(resultSet.getString("RC_AddedDate"));
pc.setM_total_amt(resultSet.getString("m_total_amt"));
memberdata.add(pc);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return memberdata;
}
Step-2
DefaultTableModel model;
model=(DefaultTableModel)jTable1.getModel();
jTable1.setAutoCreateRowSorter(true);
PC_ReciptDB pcdb=new PC_ReciptDB();
List<Personal_CoachingGS> pcgs=pcdb.selectAllInvoice(cid);
for(Personal_CoachingGS data : pcgs)
{
model.insertRow(model.getRowCount(), new Object[]{data.getM_id(),data.getM_name(),data.getM_email(),data.getM_game(),df.format(Double.parseDouble(data.getM_total_amt())),data.getM_game_sdate(),data.getM_game_edate(),df.format(Double.parseDouble(data.getM_country())),data.getM_state()});
}model.fireTableDataChanged();
0 comments:
Post a Comment