Advertisement
Guest User

asd

a guest
Dec 28th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. package ogrenci_dilekce;
  2. import java.awt.BorderLayout;
  3. import java.awt.EventQueue;
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import javax.swing.JButton;
  8. import javax.swing.JTextField;
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.MouseAdapter;
  12. import java.awt.event.MouseEvent;
  13. import java.sql.*;
  14.  
  15. public class OgrenciD extends JFrame {
  16.  
  17. private JPanel contentPane;
  18. private JTextField kurumadi;
  19. private JTextField dilekce;
  20. private JTextField adsoyad;
  21. private JTextField tarih;
  22.  
  23. /**
  24. * Launch the application.
  25. */
  26. public static void main(String[] args) {
  27. EventQueue.invokeLater(new Runnable() {
  28. public void run() {
  29. try {
  30. OgrenciD frame = new OgrenciD();
  31. frame.setVisible(true);
  32. } catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. });
  37. }
  38.  
  39. /**
  40. * Create the frame.
  41. */
  42. public OgrenciD() {
  43. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44. setBounds(100, 100, 378, 317);
  45. contentPane = new JPanel();
  46. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  47. setContentPane(contentPane);
  48. contentPane.setLayout(null);
  49.  
  50. JButton btnGnder = new JButton("G\u00F6nder");
  51. btnGnder.addMouseListener(new MouseAdapter() {
  52. @Override
  53. public void mouseClicked(MouseEvent arg0) {
  54. try{
  55. ogrenciKayit();
  56. }catch(SQLException e){
  57. System.out.println(e.toString());
  58. }
  59. }
  60. });
  61. btnGnder.addActionListener(new ActionListener() {
  62. public void actionPerformed(ActionEvent arg0) {
  63. }
  64. });
  65. btnGnder.setBounds(249, 244, 89, 23);
  66. contentPane.add(btnGnder);
  67.  
  68. kurumadi = new JTextField();
  69. kurumadi.setBounds(86, 11, 204, 20);
  70. contentPane.add(kurumadi);
  71. kurumadi.setColumns(10);
  72.  
  73. dilekce = new JTextField();
  74. dilekce.setBounds(86, 42, 204, 128);
  75. contentPane.add(dilekce);
  76. dilekce.setColumns(10);
  77.  
  78.  
  79.  
  80. adsoyad = new JTextField();
  81. adsoyad.setBounds(86, 181, 204, 20);
  82. contentPane.add(adsoyad);
  83. adsoyad.setColumns(10);
  84.  
  85.  
  86. tarih = new JTextField();
  87. tarih.setBounds(86, 209, 204, 20);
  88. contentPane.add(tarih);
  89. tarih.setColumns(10);
  90.  
  91. JButton btnGncelle = new JButton("G\u00FCncelle");
  92. btnGncelle.setBounds(139, 244, 89, 23);
  93. btnGncelle.addMouseListener(new MouseAdapter() {
  94. @Override
  95. public void mouseClicked(MouseEvent arg0) {
  96. try{
  97. ogrenciGuncelle();
  98. }catch(SQLException e){
  99. System.out.println(e.toString());
  100. }
  101. }
  102. });
  103. contentPane.add(btnGncelle);
  104.  
  105. JButton btnGetir = new JButton("Getir");
  106. btnGetir.setBounds(24, 244, 89, 23);
  107. btnGetir.addMouseListener(new MouseAdapter() {
  108. @Override
  109. public void mouseClicked(MouseEvent arg0) {
  110. try{
  111. ogrenciGetir();
  112. }catch(SQLException e){
  113. System.out.println(e.toString());
  114. }
  115. }
  116. });
  117. contentPane.add(btnGetir);
  118.  
  119. }
  120. static String conStr="jdbc:sqlserver://localhost:1433;databasename=MARKET;user=sa;password=123";
  121. private void ogrenciGuncelle() throws SQLException{
  122. try{
  123. System.out.println("Kayıt");
  124. String kurum = kurumadi.getText();
  125. String zaman = tarih.getText();
  126. String isim = adsoyad.getText();
  127. String aciklama = dilekce.getText();
  128. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  129. Connection con = DriverManager.getConnection(conStr);
  130. String str="update ogrenci set kurum='"+kurum+"' , aciklama='"+aciklama+"' , adsoyad='"+isim+"',tarih='"+zaman+"'";
  131. Statement st = con.createStatement();
  132. st.executeQuery(str);
  133. }catch(Exception e){
  134. e.printStackTrace();
  135. }
  136. }
  137.  
  138. private void ogrenciKayit() throws SQLException{
  139. try{
  140. System.out.println("Kayıt");
  141. String kurum = kurumadi.getText();
  142. String zaman = tarih.getText();
  143. String isim = adsoyad.getText();
  144. String aciklama = dilekce.getText();
  145. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  146. Connection con = DriverManager.getConnection(conStr);
  147. String str="insert into ogrenci (kurum,aciklama,adsoyad,tarih) values ('"+kurum+"','"+aciklama+"','"+isim+"','"+zaman+"')";
  148. Statement st = con.createStatement();
  149. st.executeQuery(str);
  150. }catch(Exception e){
  151. e.printStackTrace();
  152. }
  153. }
  154. private void ogrenciGetir() throws SQLException{
  155. try{
  156. System.out.println("öğrenci getir");
  157. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  158. Connection con = DriverManager.getConnection(conStr);
  159. String str="select * from ogrenci limit 1";
  160. Statement st = con.createStatement();
  161. ResultSet rs = st.executeQuery(str);
  162. while(rs.next()){
  163. kurumadi.setText(rs.getString("kurum"));
  164. tarih.setText(rs.getString("tarih"));
  165. adsoyad.setText(rs.getString("adsoyad"));
  166. dilekce.setText(rs.getString("aciklama"));
  167. }
  168. }catch(Exception e){
  169. e.printStackTrace();
  170. }
  171. }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement