ඉක්මනින්ම Database එකට Data Insert කරන Form එකක් (Vehicle Reservation සඳහා) නිර්මාණය කරගන්න හැටි බලමු.
සැ.යු. - Interface Design එක ගැන සලකා නැත. මුලිකම පෙනුම පමණි.
එක් එක් coding කුමක් සඳහාද යන්න තේරුම් ගැනීම ඔබ
සතුය.
Quick - Insert data to db through Netbeans JForm
Download File Size - 4.83MB
After Extract File - 475MB
Duration - 11min 19s
http://www.mediafire.com/?nkmh62ruhel844v
//////////////////////////////////////////////////////////////
public Home_TG(String passusername) {
initComponents();
recievedusername=passusername;
jLabel2.setText(passusername);
viewApprovedOrNot();
}
final void viewApprovedOrNot(){
try {
ResultSet rst = DB_Access.getData("select * from reserve where travel_guide='"+recievedusername+"'");
DefaultTableModel dtm = (DefaultTableModel) jTable2.getModel();
int row = dtm.getRowCount();
for(int i=0;i<row;i++){
dtm.removeRow(0);
}
while(rst.next()){
Object
ob[]={rst.getString(1),rst.getString(2),rst.getString(3),rst.getString(4),rst.getString(5),rst.getString(6)};
dtm.addRow(ob);
}
} catch (SQLException ex) {
Logger.getLogger(Home_TG.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Home_TG.class.getName()).log(Level.SEVERE, null, ex);
}
}
private
void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
if(jTextField1.getText().isEmpty() &&
jTextField2.getText().isEmpty() &&
jTextField3.getText().isEmpty()){
JOptionPane.showMessageDialog(this, "Please Fill Texts","Error",0);
} else{
String noOfPassengers = jTextField1.getText();
String fromdate = jTextField2.getText();
String todate = jTextField3.getText();
try {
ResultSet result = DB_Access.getData("select v.reg_no, v.vehicle_type,
v.no_of_seats from vehicle v where v. reg_no NOT IN (select r.vehicle
from Reserve r where ((r.from_date >= '"+fromdate+"') AND
(r.from_date <= '"+fromdate+"')) OR ((r.to_date >= '"+todate+"')
AND (r.to_date <= '"+todate+"'))) and
v.no_of_seats>="+noOfPassengers);
DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
int row = dtm.getRowCount();
for(int i=0; i<row; i++){
dtm.removeRow(0);
}
while(result.next()){
Object ob[]={result.getString(1),result.getString(2),result.getString(3)};
dtm.addRow(ob);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this,"SQL Error","Error",0);
}
}
}
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
// TODO add your handling code here:
int selected = jTable1.getSelectedRow();
jTextField4.setText(jTable1.getValueAt(selected, 0).toString());
jTextField6.setText(jTextField2.getText());
jTextField7.setText(jTextField3.getText());
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
DB_Access.setData("insert into reserve
(vehicle,travel_guide,from_date,to_date)
values('"+jTextField4.getText()+"','"+jTextField5.getText()+"','"+jTextField6.getText()+"','"+jTextField7.getText()+"')");
JOptionPane.showMessageDialog(this, "Succeeded", "Data Insert",1);
viewApprovedOrNot();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, "SQL", "Error",1);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Home_TG.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void jTable2FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTable2FocusGained
jButton3.setEnabled(true);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
String vehicle = (String) jTable2.getValueAt(jTable2.getSelectedRow(), 0);
String travel_guide = (String) jTable2.getValueAt(jTable2.getSelectedRow(), 1);
String from_date = (String) jTable2.getValueAt(jTable2.getSelectedRow(), 2);
String to_date = (String) jTable2.getValueAt(jTable2.getSelectedRow(), 3);
try {
DB_Access.setData("delete from reserve where vehicle='"+vehicle+"' and
travel_guide='"+travel_guide+"' and from_date='"+from_date+"' and
to_date='"+to_date+"'");
JOptionPane.showMessageDialog(this, "Succeeded");
viewApprovedOrNot();
} catch (SQLException ex) {
Logger.getLogger(Home_TG.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Home_TG.class.getName()).log(Level.SEVERE, null, ex);
}
}
කොහොම හරි ගොඩයන්න පෙරලෙන පිටු
ලේසියෙන්ම හොයාගන්න මෙතනින්
ඉක්මණින්ම ST II Assignment ගොඩ දාගන්නත් එපැයිනේ - Part 3
http://www.mediafire.com/?nkmh62ruhel844v
//////////////////////////////////////////////////////////////
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment