Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class week4 extends JFrame implements ActionListener{
- JButton btnIleri = new JButton(">");
- JButton btnGeri = new JButton("<");
- JButton btnBas = new JButton("<<");
- JButton btnSon = new JButton(">>");
- JButton btnSil = new JButton("SIL");
- JButton btnUpdate = new JButton("DUZENLE");
- JButton btnEkle = new JButton("EKLE");
- static JTextField txtEMPLOYEEID = new JTextField();
- static JTextField txtFIRSTNAME = new JTextField();
- static JTextField txtTITLE = new JTextField();
- static JTextField txtLASTNAME = new JTextField();
- static JTextField txtHOMEPHONE = new JTextField();
- JLabel lblEMPLOYEEID = new JLabel("EMPLOYEEID:");
- JLabel lblFIRSTNAME = new JLabel("FIRSTNAME:");
- JLabel lblTITLE = new JLabel("TITLE:");
- JLabel lblLASTNAME = new JLabel("LASTNAME:");
- JLabel lblHOMEPHONE = new JLabel("HOMEPHONE:");
- JLabel lblbos = new JLabel();
- static Connection connection = null;
- static Statement st = null;
- static ResultSet rs = null;
- week4()
- {
- super("Employee Info");
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- setLayout(new GridLayout(9,2)); // satir, sutun
- btnIleri.addActionListener(this);
- btnBas.addActionListener(this);
- btnSon.addActionListener(this);
- btnGeri.addActionListener(this);
- btnSil.addActionListener(this);
- btnUpdate.addActionListener(this);
- btnEkle.addActionListener(this);
- add(btnBas);
- add(btnSon);
- add(btnGeri);
- add(btnIleri);
- add(btnSil);
- add(btnUpdate);
- add(btnEkle);
- add(lblbos);
- add(lblEMPLOYEEID);
- txtEMPLOYEEID.setEditable(false);
- add(txtEMPLOYEEID);
- add(lblFIRSTNAME);
- add(txtFIRSTNAME);
- add(lblLASTNAME);
- add(txtLASTNAME);
- add(lblTITLE);
- add(txtTITLE);
- add(lblHOMEPHONE);
- add(txtHOMEPHONE);
- setSize(450, 200);
- setVisible(true);
- ConnectionStuff();
- }
- static void ConnectionStuff(){
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- String serverName = "//193.255.85.26";
- String portNumber = "1521";
- String dbName = "ORCL";
- String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber
- + "/" + dbName;
- String username = "ozge";
- String password = "ozge";
- connection = DriverManager.getConnection(url, username, password);
- System.out.println("TADA!!");
- st=connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
- �lkBilgiler();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- static void �lkBilgiler(){
- try {
- rs=st.executeQuery("select * from employees");
- rs.next();
- VerileriGoster();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- static void VerileriGoster(){
- try {
- txtEMPLOYEEID.setText(rs.getString("EMPLOYEEID"));
- txtFIRSTNAME.setText(rs.getString("FIRSTNAME"));
- txtTITLE.setText(rs.getString("TITLE"));
- txtLASTNAME.setText(rs.getString("LASTNAME"));
- txtHOMEPHONE.setText(rs.getString("HOMEPHONE"));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- new week4();
- }
- public void actionPerformed(ActionEvent e) {
- if (e.getActionCommand().equals(">")) {
- try {
- rs.next();
- VerileriGoster();
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- else if (e.getActionCommand().equals("<")) {
- try
- {
- rs.previous();
- VerileriGoster();
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- }
- else if (e.getActionCommand().equals("<<")) {
- try
- {
- rs.first(); //en basa gider
- VerileriGoster();
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- else if (e.getActionCommand().equals(">>")) {
- try
- {
- rs.last();
- VerileriGoster();
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- else if (e.getActionCommand().equals("SIL")) {
- String query = "DELETE FROM EMPLOYEES WHERE EMPLOYEEID = ?";
- try
- {
- PreparedStatement ps = connection.prepareStatement(query);
- ps.setInt(1, Integer.parseInt(txtEMPLOYEEID.getText()));
- ps.executeUpdate();
- ps.close();
- JOptionPane.showMessageDialog(null, "Silme i�lemi ba�arili.");
- VerileriGoster();
- }
- catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- else if (e.getActionCommand().equals("DUZENLE")) {
- String query = "UPDATE EMPLOYEES SET FIRSTNAME=?, LASTNAME=?, TITLE=?, HOMEPHONE=? WHERE EMPLOYEEID=?";
- try
- {
- PreparedStatement ps = connection.prepareStatement(query);
- ps.setString(1, txtFIRSTNAME.getText());
- ps.setString(2, txtLASTNAME.getText());
- ps.setString(3, txtTITLE.getText());
- ps.setString(4, txtHOMEPHONE.getText());
- ps.setInt(5, Integer.parseInt(txtEMPLOYEEID.getText()));
- ps.executeUpdate();
- ps.close();
- JOptionPane.showMessageDialog(null, "Update ba�arili");
- VerileriGoster();
- }
- catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- else if (e.getActionCommand().equals("EKLE")) {
- if(txtEMPLOYEEID.isEditable()) //ikinci tiklandiginda database'e insert eder
- {
- String query = "INSERT INTO EMPLOYEES (EMPLOYEEID, FIRSTNAME, LASTNAME, TITLE, HOMEPHONE) VALUES(?,?,?,?,?)";
- try
- {
- PreparedStatement ps = connection.prepareStatement(query);
- ps.setInt(1, Integer.parseInt(txtEMPLOYEEID.getText()));
- ps.setString(2, txtFIRSTNAME.getText());
- ps.setString(3, txtLASTNAME.getText());
- ps.setString(4, txtTITLE.getText());
- ps.setString(5, txtHOMEPHONE.getText());
- ps.executeUpdate();
- ps.close();
- JOptionPane.showMessageDialog(null, "Insert i�lemi� ba�arili");
- }
- catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- VerileriGoster();
- txtEMPLOYEEID.setEditable(false);
- }
- else //ilk kez basildi�inda, txtEMPLOYEEID'yi acar ve textfield'larin hepsini bosaltir.
- {
- txtEMPLOYEEID.setEditable(true);
- txtEMPLOYEEID.setText("");
- txtFIRSTNAME.setText("");
- txtLASTNAME.setText("");
- txtTITLE.setText("");
- txtHOMEPHONE.setText("");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment