Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ogrenci_dilekce;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JButton;
- import javax.swing.JTextField;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.sql.*;
- public class OgrenciD extends JFrame {
- private JPanel contentPane;
- private JTextField kurumadi;
- private JTextField dilekce;
- private JTextField adsoyad;
- private JTextField tarih;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- OgrenciD frame = new OgrenciD();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public OgrenciD() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 378, 317);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JButton btnGnder = new JButton("G\u00F6nder");
- btnGnder.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- try{
- ogrenciKayit();
- }catch(SQLException e){
- System.out.println(e.toString());
- }
- }
- });
- btnGnder.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- btnGnder.setBounds(249, 244, 89, 23);
- contentPane.add(btnGnder);
- kurumadi = new JTextField();
- kurumadi.setBounds(86, 11, 204, 20);
- contentPane.add(kurumadi);
- kurumadi.setColumns(10);
- dilekce = new JTextField();
- dilekce.setBounds(86, 42, 204, 128);
- contentPane.add(dilekce);
- dilekce.setColumns(10);
- adsoyad = new JTextField();
- adsoyad.setBounds(86, 181, 204, 20);
- contentPane.add(adsoyad);
- adsoyad.setColumns(10);
- tarih = new JTextField();
- tarih.setBounds(86, 209, 204, 20);
- contentPane.add(tarih);
- tarih.setColumns(10);
- JButton btnGncelle = new JButton("G\u00FCncelle");
- btnGncelle.setBounds(139, 244, 89, 23);
- btnGncelle.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- try{
- ogrenciGuncelle();
- }catch(SQLException e){
- System.out.println(e.toString());
- }
- }
- });
- contentPane.add(btnGncelle);
- JButton btnGetir = new JButton("Getir");
- btnGetir.setBounds(24, 244, 89, 23);
- btnGetir.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- try{
- ogrenciGetir();
- }catch(SQLException e){
- System.out.println(e.toString());
- }
- }
- });
- contentPane.add(btnGetir);
- }
- static String conStr="jdbc:sqlserver://localhost:1433;databasename=MARKET;user=sa;password=123";
- private void ogrenciGuncelle() throws SQLException{
- try{
- System.out.println("Kayıt");
- String kurum = kurumadi.getText();
- String zaman = tarih.getText();
- String isim = adsoyad.getText();
- String aciklama = dilekce.getText();
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- Connection con = DriverManager.getConnection(conStr);
- String str="update ogrenci set kurum='"+kurum+"' , aciklama='"+aciklama+"' , adsoyad='"+isim+"',tarih='"+zaman+"'";
- Statement st = con.createStatement();
- st.executeQuery(str);
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- private void ogrenciKayit() throws SQLException{
- try{
- System.out.println("Kayıt");
- String kurum = kurumadi.getText();
- String zaman = tarih.getText();
- String isim = adsoyad.getText();
- String aciklama = dilekce.getText();
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- Connection con = DriverManager.getConnection(conStr);
- String str="insert into ogrenci (kurum,aciklama,adsoyad,tarih) values ('"+kurum+"','"+aciklama+"','"+isim+"','"+zaman+"')";
- Statement st = con.createStatement();
- st.executeQuery(str);
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- private void ogrenciGetir() throws SQLException{
- try{
- System.out.println("öğrenci getir");
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- Connection con = DriverManager.getConnection(conStr);
- String str="select * from ogrenci limit 1";
- Statement st = con.createStatement();
- ResultSet rs = st.executeQuery(str);
- while(rs.next()){
- kurumadi.setText(rs.getString("kurum"));
- tarih.setText(rs.getString("tarih"));
- adsoyad.setText(rs.getString("adsoyad"));
- dilekce.setText(rs.getString("aciklama"));
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement