private void createAuditTable() { try { sta.setText("Creating AUDIT table"); Connection connection = DBConnect.Connect(); String sql = "CREATE TABLE IF NOT EXISTS `audit` (\n" + " `id` varchar(10) NOT NULL,\n" + " `audit_1` int(11) NOT NULL,\n" + " `audit_2` int(11) NOT NULL,\n" + " `audit_3` int(11) NOT NULL,\n" + " `audit_4` int(11) NOT NULL,\n" + " `audit_5` int(11) NOT NULL,\n" + " `audit_6` int(11) NOT NULL,\n" + " `audit_7` int(11) NOT NULL,\n" + " `audit_8` int(11) NOT NULL,\n" + " `audit_9` int(11) NOT NULL,\n" + " `audit_10` int(11) NOT NULL\n" + ")"; Statement statement = connection.createStatement(); statement.executeUpdate(sql); statement.close(); // JOptionPane.showMessageDialog(null, "Audit table has been created successfully", "System // Message", JOptionPane.INFORMATION_MESSAGE); sta.setText("Audit table has been created successfully"); } catch (SQLException | HeadlessException e) { sta.setText(e.getMessage()); // JOptionPane.showMessageDialog(null, e.getMessage()); } }
private void createTlfb_126Table() { try { sta.setText("Creating TLFB 12 table"); Connection connection = DBConnect.Connect(); String sql = "CREATE TABLE IF NOT EXISTS `tlfb_12` (\n" + " `id` varchar(10) NOT NULL,\n" + " `tlfb_1` int(11) NOT NULL,\n" + " `tlfb_2` int(11) NOT NULL,\n" + " `tlfb_3` int(11) NOT NULL,\n" + " `tlfb_4` int(11) NOT NULL,\n" + " `tlfb_5` int(11) NOT NULL,\n" + " `tlfb_6` int(11) NOT NULL,\n" + " `tlfb_7` int(11) NOT NULL,\n" + " `tlfb_8` int(11) NOT NULL,\n" + " `tlfb_9` int(11) NOT NULL,\n" + " `tlfb_10` int(11) NOT NULL,\n" + " `tlfb_11` int(11) NOT NULL,\n" + " `tlfb_12` int(11) NOT NULL,\n" + " `tlfb_13` int(11) NOT NULL,\n" + " `tlfb_14` int(11) NOT NULL,\n" + " `tlfb_15` int(11) NOT NULL,\n" + " `tlfb_16` int(11) NOT NULL,\n" + " `tlfb_17` int(11) NOT NULL,\n" + " `tlfb_18` int(11) NOT NULL,\n" + " `tlfb_19` int(11) NOT NULL,\n" + " `tlfb_20` int(11) NOT NULL,\n" + " `tlfb_21` int(11) NOT NULL,\n" + " `tlfb_22` int(11) NOT NULL,\n" + " `tlfb_23` int(11) NOT NULL,\n" + " `tlfb_24` int(11) NOT NULL,\n" + " `tlfb_25` int(11) NOT NULL,\n" + " `tlfb_26` int(11) NOT NULL,\n" + " `tlfb_27` int(11) NOT NULL,\n" + " `tlfb_28` int(11) NOT NULL,\n" + " `tlfb_29` int(11) NOT NULL,\n" + " `tlfb_30` int(11) NOT NULL,\n" + " `tlfb_31` int(11) NOT NULL\n" + ")"; Statement statement = connection.createStatement(); statement.executeUpdate(sql); statement.close(); // JOptionPane.showMessageDialog(null, "TLFB table has been created successfully", // "System Message", JOptionPane.INFORMATION_MESSAGE); sta.setText("TLFB table has been created successfully"); } catch (SQLException | HeadlessException e) { // JOptionPane.showMessageDialog(null, e.getMessage()); sta.setText(e.getMessage()); } }
private void insertToTable() { try { // Statement stmt; Connection conn1 = DBConnect.Connect(); // ResultSet rs=null; PreparedStatement pst1 = null; String sql = "INSERT INTO user (user_name, password) VALUES(?, ?);"; pst1 = conn1.prepareStatement(sql); pst1.setString(1, USER.getText()); pst1.setString(2, PASS.getText()); pst1.execute(); JOptionPane.showMessageDialog(null, "Saved"); } catch (SQLException | HeadlessException ex) { sta.setText(ex.getMessage()); // JOptionPane.showMessageDialog(null, ex.getMessage()); } }
private void createUserTable() { try { sta.setText("Creating User table"); Connection connection = DBConnect.Connect(); String sql = "CREATE TABLE `user` (`user_name` varchar(10) NOT NULL,`password` varchar(10) NOT NULL) "; Statement statement = connection.createStatement(); statement.executeUpdate(sql); statement.close(); // JOptionPane.showMessageDialog(null, "User table has been created successfully", "System // Message", JOptionPane.INFORMATION_MESSAGE); sta.setText("User table has been created successfully"); } catch (SQLException | HeadlessException e) { sta.setText(e.getMessage()); // JOptionPane.showMessageDialog(null, e.getMessage()); } }
private void createPatientTable() { try { sta.setText("Creating Patient table"); Connection connection = DBConnect.Connect(); String sql = "CREATE TABLE IF NOT EXISTS `patient` (\n" + " `id` varchar(10) NOT NULL,\n" + " `name` varchar(30) NOT NULL,\n" + " `gender` varchar(10) NOT NULL,\n" + " `religion` varchar(20) NOT NULL,\n" + " `race` varchar(20) NOT NULL,\n" + " `town` varchar(20) NOT NULL,\n" + " `employeement` varchar(30) NOT NULL,\n" + " `date_birth` date NOT NULL,\n" + " `register_date` date NOT NULL,\n" + " `date_t6` date DEFAULT NULL,\n" + " `date_t12` date DEFAULT NULL,\n" + " `email` varchar(30) NOT NULL,\n" + " `telephone` varchar(15) NOT NULL,\n" + " `contact_person` varchar(100) NOT NULL,\n" + " `adress` varchar(70) NOT NULL,\n" + " `refered_by` varchar(20) NOT NULL,\n" + " `age` varchar(15) NOT NULL,\n" + " `diognosis` varchar(50) NOT NULL,\n" + " `level_motivation` varchar(30) NOT NULL,\n" + " PRIMARY KEY (`id`)\n" + ") "; Statement statement = connection.createStatement(); statement.executeUpdate(sql); statement.close(); // JOptionPane.showMessageDialog(null, "Patient table has been created successfully", "System // Message", JOptionPane.INFORMATION_MESSAGE); sta.setText("Patient table has been created successfully"); } catch (SQLException | HeadlessException e) { // JOptionPane.showMessageDialog(null, e.getMessage()); sta.setText(e.getMessage()); } }
@Override public int crear() { int retorno = 0; Conexion con = new Conexion(); con.conectate(); Connection conx = con.getConn(); try { Statement st = conx.createStatement(); String sqlInsert = "INSERT INTO alumno VALUES (default,?,?,?,?,?,?);"; PreparedStatement pstmt = conx.prepareStatement(sqlInsert, PreparedStatement.RETURN_GENERATED_KEYS); pstmt.setString(1, this.matricula); pstmt.setString(2, this.getNombre()); pstmt.setString(3, this.getApellidoPaterno()); pstmt.setString(4, this.getApellidoMaterno()); pstmt.setString(5, this.getFechaNacimiento()); pstmt.setString(6, this.getDireccion()); int n = pstmt.executeUpdate(); if (n > 0) { JOptionPane.showMessageDialog(null, "Guardado con Exito"); } ResultSet rs = pstmt.getGeneratedKeys(); if (rs != null && rs.next()) { this.setId(rs.getInt(1)); } else { retorno = -1; } conx.close(); } catch (SQLException | HeadlessException e) { System.out.println(e.getMessage()); retorno = -1; } return retorno; }
private void createDatabase() { try { sta.setText("Creating Database"); String databaseName = "annexurei_1"; String userName = "******"; String password = ""; String url = "jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull"; Connection connection = DriverManager.getConnection(url, userName, password); String sql = "CREATE DATABASE " + databaseName; Statement statement = connection.createStatement(); statement.executeUpdate(sql); statement.close(); // JOptionPane.showMessageDialog(null, databaseName + " Database has been created // successfully", "System Message", JOptionPane.INFORMATION_MESSAGE); sta.setText(databaseName + " Database has been created successfully"); } catch (SQLException | HeadlessException e) { sta.setText(e.getMessage()); // JOptionPane.showMessageDialog(null, e.getMessage()); } }
private void createQlefQs_6fTable() { try { sta.setText("Creating Q LEF Q SF 6 table"); Connection connection = DBConnect.Connect(); String sql = "CREATE TABLE IF NOT EXISTS `q_lef_q_sf_6` (\n" + " `id` varchar(10) NOT NULL,\n" + " `q_lef_q_sf_1` int(11) NOT NULL,\n" + " `q_lef_q_sf_2` int(11) NOT NULL,\n" + " `q_lef_q_sf_3` int(11) NOT NULL,\n" + " `q_lef_q_sf_4` int(11) NOT NULL,\n" + " `q_lef_q_sf_5` int(11) NOT NULL,\n" + " `q_lef_q_sf_6` int(11) NOT NULL,\n" + " `q_lef_q_sf_7` int(11) NOT NULL,\n" + " `q_lef_q_sf_8` int(11) NOT NULL,\n" + " `q_lef_q_sf_9` int(11) NOT NULL,\n" + " `q_lef_q_sf_10` int(11) NOT NULL,\n" + " `q_lef_q_sf_11` int(11) NOT NULL,\n" + " `q_lef_q_sf_12` int(11) NOT NULL,\n" + " `q_lef_q_sf_13` int(11) NOT NULL,\n" + " `q_lef_q_sf_14` int(11) NOT NULL,\n" + " `q_lef_q_sf_15` int(11) NOT NULL,\n" + " `q_lef_q_sf_16` int(11) NOT NULL\n" + ") "; Statement statement = connection.createStatement(); statement.executeUpdate(sql); statement.close(); // JOptionPane.showMessageDialog(null, "Q LEF QSF 6 table has been created // successfully", "System Message", JOptionPane.INFORMATION_MESSAGE); sta.setText("Q LEF QSF 6 table has been created successfully"); } catch (SQLException | HeadlessException e) { // JOptionPane.showMessageDialog(null, e.getMessage()); sta.setText(e.getMessage()); } }