หน้าแรก
 การบ้าน
  C/C++ new
  Java new
  Windows Phone
  แจ้งเรื่องที่ต้องการ
 บทความ
  .NET
  Android
  Blackberry
  C++Builder
  Delphi
  Java
  Mobile
  Open Source
  Pocket PC
  Visual Basic
  Web
  Windows Phone
  Others
 แบบเรียนฟรี
  ASP
  ASP.NET Webmatrix
  C++
  eVB
  J2ME
  Java
  PHP
 ซอร์สโค้ด
  Android
  ASP
  C++
  VC++
  CGI-Perl
  Delphi
  Java
  jQuery
  PHP
  Visual Basic
  .NET
 บริการจากเรา
  เปิดท้าย... ขายโค้ด
  Freeware
  อัตราค่าโฆษณา
  รายชื่อลูกค้า
  สถิติผู้เข้าเว็บ
 ดาว์นโหลด
 ค้นหาข้อมูล
 กระดานสนทนา
  .NET
  C/C++
  Delphi
  Java
  Palm/PocketPC
  Visual Basic
  Web
  อื่นๆ
 กระดานงาน
 ลิงค์เว็บ
 เกี่ยวกับผม
 อัตราค่าโฆษณา
Social Network

Facebook  Twitter  YouTube
 New Article
 Webboard
 Freelanceboard
Freeware
โปรแกรมเบอร์ดี (BerDee)
โปรแกรมเบอร์ดี (Android)
เกมส์เป่ายิ้งฉุบ
เกมส์เป่ายิ้งฉุบ(Android)
WebcamMonitor
WebcamMonitor(Windows)
scSendMail
scSendMail(Windows)
MSN Caption
MSN Caption(Windows)
  Freelance comment
  ติดต่อสอบถามมาได้ตลอดนะ...
2015-07-29 13:35:58
  ถ้าผมต้องการเว็บที่พัฒน...
2015-01-18 15:33:54
  ถ้าผมต้องการเว็บที่พัฒน...
2015-01-18 15:32:51
  ติดต่อสอบถามเข้ามาได้นะ...
2014-01-06 12:47:38
  ถ้ายังหาคนสอนไม่ได้ ก็ลอ...
2013-07-06 01:04:37
  สนใจส่งขอบเขตมาคุยราคาก...
2013-03-24 18:54:20
  ถ้ายังไม่มีคนรับงานติดต...
2012-12-16 19:18:14
  สนใจคะ ติดต่อ 0905076277...
2012-11-12 11:07:46
  รับทำโปรเจ็คนักศึกษาหรื...
2012-10-29 03:10:46
  sukit_te34@hotmail.com...
2012-10-29 03:09:36
  Webboard comment
  เขียนโปรแกรมภาษาจาวา
1.โ...

2023-09-12 11:40:28
  ต้องลอง debug ดูเองครับ
ไล่...

2023-06-08 18:03:06
  ร้านค้าแห่งหนึ่ง จะต้องน...
2021-09-21 08:47:08
  จงเขียนโปรแกรมดำเนินการ...
2021-05-07 15:06:11
  จงเขียนโปรแกรมสำหรับคำน...
2021-03-09 14:21:45
  ขอดู...
2021-01-04 23:56:45
  ขอโค้ดเพื่อทำการเรียนกา...
2020-12-09 23:02:09
  แล้ว ?...
2020-12-09 10:56:34
  จ้า...
2020-10-18 16:53:21
  พอดีผมเหลื่อแค่ตัดสต๊อก...
2020-05-31 21:49:43
  Homework comment
  เขียนโปรแกรมเพื่อรับค่า...
2022-02-24 10:45:17
  จากโค้ดนี้อะครับ พอดีลอง...
2021-03-22 01:22:39
  จากโค้ดนี้อะครับ พอดีลอง...
2021-03-22 01:22:39
  โจทย์การบ้าน c++ เขียนรูปแ...
2020-04-06 11:01:33
  แบบนี้ขอเป็น ภาษา php หน่อย...
2019-09-18 14:36:34
  ผมไม่อยากให้คุณได้คะแนน...
2019-04-27 01:29:07
  อาจารย์เขาบอกแนวข้อสอบม...
2019-04-27 00:44:29
  ขอสอบถามการเขียน c++ ครับ เ...
2018-04-02 12:19:21
  โค้ดตัวอย่างศึกษาให้เข้...
2017-11-26 14:50:05
  คำนวณค่าน้ำโดยรับค่ามิเ...
2017-11-20 23:15:26
  Article comment
  เท่าที่อ่าน error คือพื้นที่...
2022-03-23 13:56:48
  เรียน สอบถามปัญหา กับ อ.คร...
2022-01-24 17:39:49
  ต้องการ ให้เขียน โปรแกรม ...
2019-12-09 11:39:58
  รับเขียน arx จาก vc++ 2017 ล็อคโปร...
2019-09-19 09:48:09
  ทำการ register ไฟล์ที่ชื่อ mswinsck.oc...
2019-09-17 14:05:56
  ใน vb 6 ไม่มี component winsock เลยค่ะ ส...
2019-09-03 10:31:02
  รบกวนขอสอบถามหน่อยนะครั...
2019-03-04 05:31:04
  สามารถนำตัวหนังสือจากภา...
2018-12-25 08:54:32
  มีcode ของ VB ไหมค่ะ ถ้ามีรบกว...
2017-09-28 16:50:02
  น่าจะได้ครับ ไม่เคยลอง
...

2017-07-11 09:59:35
  9Mcode comment

Link Exchange

อัตราค่าโฆษณา
 
 Webboard

- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -

กระทู้ #3533 [Java] (จาก IP: 124.122.155.46)

รบกวนช่วยดูว่าแก้ไขตรงไหนถึงจะไม่ซ้อนครับ

package com.java.myapp;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

public class MyDetail extends JDialog {


/**
* Create the dialog.
*/
public MyDetail(final String sid) {
setTitle("Customer_nresu");
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setBounds(100, 100, 760, 550);
getContentPane().setLayout(null);
setResizable(false);

// Header Customer Detail
JLabel hCustomerAdd = new JLabel("Insert Customer");
hCustomerAdd.setBounds(144, 21, 132, 14);
getContentPane().add(hCustomerAdd);

//*** Header ***//
JLabel hid = new JLabel("id :");
hid.setBounds(100, 51, 89, 20);
getContentPane().add(hid);

JLabel hname = new JLabel("name :");
hname.setBounds(100, 81, 120, 20);
getContentPane().add(hname);

JLabel haddress = new JLabel("address :");
haddress.setBounds(100, 111, 89, 20);
getContentPane().add(haddress);

JLabel htel = new JLabel("tel :");
htel.setBounds(100, 141, 89, 20);
getContentPane().add(htel);

JLabel hEmail = new JLabel("Email :");
hEmail.setBounds(100, 171, 89, 20);
getContentPane().add(hEmail);

JLabel htxtregister_of_commercial_No = new JLabel("register of commercial No. :");
htxtregister_of_commercial_No.setBounds(100, 201, 200, 20);
getContentPane().add(htxtregister_of_commercial_No);

JLabel hcapital_investment = new JLabel("capital of register :");
hcapital_investment.setBounds(100, 231, 150, 20);
getContentPane().add(hcapital_investment);

JLabel hวงเงิน = new JLabel("วงเงิน :");
hวงเงิน.setBounds(100, 261, 89, 20);
getContentPane().add(hวงเงิน);

JLabel hsellid = new JLabel("sellid :");
hsellid.setBounds(100, 291, 89, 20);
getContentPane().add(hsellid);

//*** Detail ***//
JLabel lblid = new JLabel("Id");
lblid.setBounds(257, 51, 89, 20);
getContentPane().add(lblid);

JLabel lblname = new JLabel("lblName");
lblname.setBounds(257, 81, 200, 20);
getContentPane().add(lblname);

JLabel lbladdress = new JLabel("lblAddress");
lbladdress.setBounds(257, 111, 400, 20);
getContentPane().add(lbladdress);

JLabel lbltel = new JLabel("lblTel");
lbltel.setBounds(257, 141, 100, 20);
getContentPane().add(lbltel);

JLabel lblEmail = new JLabel("lblEmail");
lblEmail.setBounds(257, 171, 150, 20);
getContentPane().add(lblEmail);

JLabel lblregister_of_commercial_No = new JLabel("lblRegisty of commercial No.");
lblregister_of_commercial_No.setBounds(257, 201, 100, 20);
getContentPane().add(lblregister_of_commercial_No);

JLabel lblcapital_investment = new JLabel("lblCapital investment");
lblcapital_investment.setBounds(257, 231, 150, 20);
getContentPane().add(lblcapital_investment);

JLabel lblวงเงิน = new JLabel("lblวงเงิน");
lblวงเงิน.setBounds(257, 261, 120, 20);
getContentPane().add(lblวงเงิน);

JLabel lblsellid = new JLabel("lblsellid");
lblsellid.setBounds(257, 291, 120, 20);
getContentPane().add(lblsellid);

//*** Bind Data ***//
Connection connect = null;
Statement s = null;

try {
Class.forName("com.mysql.jdbc.Driver");

connect = DriverManager.getConnection("jdbc:mysql://localhost/history" +
"?user=root&password=027434323");

s = connect.createStatement();

String sql = "SELECT * FROM customer_nresu " +
"WHERE id = '" + sid + "' ";

ResultSet rec = s.executeQuery(sql);

if(rec != null) {
rec.next();
lblid.setText(rec.getString("Id"));
lblname.setText(rec.getString("Name"));
lbladdress.setText(rec.getString("Address"));
lbltel.setText(rec.getString("Tel"));
lblEmail.setText(rec.getString("Email"));
lblregister_of_commercial_No.setText(rec.getString("Register_of_commercial_No"));
lblcapital_investment.setText(rec.getString("Capital_investment"));
lblวงเงิน.setText(rec.getString("วงเงิน"));
lblsellid.setText(rec.getString("Sellid"));
}
rec.close();

} catch (Exception e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, e.getMessage());
e.printStackTrace();
}

try {
if(s != null) {
s.close();
connect.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
e.printStackTrace();
}




// Close Button
JButton btnClose = new JButton("Close");
btnClose.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});

btnClose.setBounds(400, 400, 69, 23);
getContentPane().add(btnClose);
JButton btnEdit = new JButton("Edit");
btnEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
UpdateForm();

}

private void UpdateForm(){



setTitle("Customer_nresu");
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setBounds(100, 100, 760, 550);
getContentPane().setLayout(null);
setResizable(false);

// Header Customer Update
JLabel hCustomerUpdate = new JLabel("Customer Update");
hCustomerUpdate.setBounds(144, 21, 132, 20);
getContentPane().add(hCustomerUpdate);

// *** Header ***//
JLabel hid = new JLabel("ID :");
hid.setBounds(100, 51, 89, 20);
getContentPane().add(hid);

JLabel hname = new JLabel("Name :");
hname.setBounds(100, 81, 89, 20);
getContentPane().add(hname);

JLabel haddress = new JLabel("Address :");
haddress.setBounds(100, 111, 89, 20);
getContentPane().add(haddress);

JLabel htel = new JLabel("Tel :");
htel.setBounds(100, 141, 89, 20);
getContentPane().add(htel);

JLabel hemail = new JLabel("Email :");
hemail.setBounds(100, 171, 89, 20);
getContentPane().add(hemail);

JLabel hregister_of_commercial_No = new JLabel("registy of commercial No. :");
hregister_of_commercial_No.setBounds(100, 201, 89, 20);
getContentPane().add(hregister_of_commercial_No);

JLabel hcapital_investment = new JLabel("capital :");
hcapital_investment.setBounds(100, 231, 89, 20);
getContentPane().add(hcapital_investment);

JLabel hวงเงิน = new JLabel("วงเงิน :");
hวงเงิน.setBounds(100, 261, 89, 20);
getContentPane().add(hวงเงิน);

JLabel hsellid = new JLabel("Sellid :");
hsellid.setBounds(100, 291, 89, 20);
getContentPane().add(hsellid);


final JLabel txtid = new JLabel("id");
txtid.setBounds(207, 51, 99, 20);
getContentPane().add(txtid);


final JTextField txtname = new JTextField("");
txtname.setBounds(207, 81, 99, 20);
getContentPane().add(txtname);

final JTextField txtaddress = new JTextField("");
txtaddress.setBounds(207, 111, 99, 20);
getContentPane().add(txtaddress);

final JTextField txttel = new JTextField("");
txttel.setBounds(207, 141, 99, 20);
getContentPane().add(txttel);


final JTextField txtemail = new JTextField("");
txtemail.setBounds(207, 171, 99, 20);
getContentPane().add(txtemail);


final JTextField txtregister_of_commercial_No = new JTextField("");
txtregister_of_commercial_No.setBounds(207, 201, 99, 20);
getContentPane().add(txtregister_of_commercial_No);


final JTextField txtcapital_investment = new JTextField("");
txtcapital_investment.setBounds(207, 231, 99, 20);
getContentPane().add(txtcapital_investment);


final JTextField txtวงเงิน = new JTextField("");
txtวงเงิน.setBounds(207, 261, 99, 20);
getContentPane().add(txtวงเงิน);

final JTextField txtsellid = new JTextField("");
txtsellid.setBounds(207, 291, 99, 20);
getContentPane().add(txtsellid);


Connection connect = null;
Statement s = null;


try {
Class.forName("com.mysql.jdbc.Driver");

connect = DriverManager
.getConnection("jdbc:mysql://localhost/history"
+ "?user=root&password=027434323");

s = connect.createStatement();

String sql = "SELECT * FROM customer_nresu " + "WHERE id = '"
+ sid + "' ";

ResultSet rec = s.executeQuery(sql);

if (rec != null) {
rec.next();
txtid.setText(rec.getString("ID"));
txtname.setText(rec.getString("Name"));
txtaddress.setText(rec.getString("Address"));
txttel.setText(rec.getString("Tel"));
txtemail.setText(rec.getString("email"));
txtregister_of_commercial_No.setText(rec.getString("register_of_commercial_No"));
txtcapital_investment.setText(rec.getString("capital_investment"));
txtวงเงิน.setText(rec.getString("วงเงิน"));
txtsellid.setText(rec.getString("Sellid"));
}
rec.close();

} catch (Exception e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, e.getMessage());
e.printStackTrace();
}

try {
if (s != null) {
s.close();
connect.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
e.printStackTrace();


}

// Save Button
JButton btnSave = new JButton("Save");
btnSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
SaveData(txtid.getText(), txtname.getText(),
txtaddress.getText(),txttel.getText(),
txtemail.getText(),txtregister_of_commercial_No.getText(),
txtcapital_investment.getText(), txtวงเงิน.getText(),
txtsellid.getText());

dispose();
}
});
btnSave.setBounds(131, 400, 69, 23);
getContentPane().add(btnSave);

// Button Close
JButton btnClose = new JButton("Close");
btnClose.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnClose.setBounds(217, 400, 69, 23);
getContentPane().add(btnClose);

}



// Update
private void SaveData(String strid, String strname, String straddress,String stremail, String strtel,
String strregister_of_commercial_No, String strcapital_investment, String strวงเงิน, String strsellid) {

Connection connect = null;
Statement s = null;

try {
Class.forName("com.mysql.jdbc.Driver");

connect = DriverManager.getConnection("jdbc:mysql://localhost/history" +
"?user=root&password=027434323");

s = connect.createStatement();

String sql = "UPDATE customer_nresu " +
"SET ID = '" + strid + "' " +
", Name = '" + strname + "' " +
", Address = '" + straddress + "' " +
", Tel = '" + strtel + "' " +
", Email = '" + stremail + "' " +
", register_of_commercial_No = '" + strregister_of_commercial_No +"' " +
", capital_investment = '" + strcapital_investment + "' " +
", วงเงิน = '" + strวงเงิน + "' " +
", Sellid = '" + strsellid + "' " +
" WHERE ID = '"+strid+"' ";
s.execute(sql);

JOptionPane.showMessageDialog(null, "Record Update Successfully");

} catch (Exception e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, e.getMessage());
e.printStackTrace();
}

try {
if(s != null) {
s.close();
connect.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage());
e.printStackTrace();
}

}
});
btnEdit.setBounds(280, 400, 69, 23);
getContentPane().add(btnEdit);

}
}
จากคุณ : Jii / gotji26000@gmail.com [2014-11-26 10:32:13]  

58.11.98.241 ความคิดเห็น #29169 (จาก IP: 58.11.98.241)
ผมว่าไม่ซับซ้อนนะ
แต่ถ้าอยากให้โค้ดออกมาแยกเป็นส่วนๆ ก็ลองศึกษาพวก MVC อาจช่วยท่านได้
จากคุณ : maddog [2014-11-26 18:01:59]
ตอบกระทู้
  • ห้ามการโฆษณา หากต้องการติดต่อหาลูกค้า ติดต่อโฆษณาโดยตรงได้ที่ webmaster@sourcecode.in.th
  • ห้ามใช้คำหยาบและคำพูดที่ไม่เหมาะสม
  • ขอสงวนสิทธิหากตรวจพบ ข้อความที่ไม่เหมาะสม ข้อความนั้นจะถูกลบทันที
ชื่อ
อีเมล์
รายละเอียด

- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -

 
 
คลิปสอนเขียนโปรแกรม
เรียนเขียนโปรแกรมดอทเน็ต
เรียนเขียนโปรแกรมแอนดรอยด์
เรียนเขียนโปรแกรมเบล็คเบอร์รี่
เรียนเขียนโปรแกรมซี ซีพลัสพลัส
เรียนเขียนโปรแกรมจาวา
เรียนการใช้งานลินุกส์
เรียนการเขียนโปรแกรมวินโดว์โฟน
เรียนการเขียนโปรแกรมพีเฮชพี มายเอสคิวเอล
อัตราค่าโฆษณา
 
Tutorial
eVB Tutorial
ASP.NET Webmatrix Tutorial
J2ME Tutorial
C++  Tutorial
Java  Tutorial
PHP Tutorial
ASP Tutorial
 
แบบสำรวจ

Home - Article - Tutorial - Sourcecode - Dev Handbook - Search - WebBoard - Links - About Us

สงวนลิขสิทธิ์ ห้ามคัดลอก ทำซ้ำ แก้ไข ดัดแปลง ไม่ว่าในรูปแบบใด โดยไม่ได้รับอนุญาตเป็นลายลักษณ์อักษร
เลขทะเบียนพาณิชย์อิเล็กทรอนิกส์จากกระทรวงพาณิชย์: 7100503002000
Copyright 2001 SourceCode.in.th