/** Method declaration Adjust this method for large strings...ie multi megabtypes. */ void execute() { String sCmd = null; if (4096 <= ifHuge.length()) { sCmd = ifHuge; } else { sCmd = txtCommand.getText(); } if (sCmd.startsWith("-->>>TEST<<<--")) { testPerformance(); return; } String g[] = new String[1]; lTime = System.currentTimeMillis(); try { sStatement.execute(sCmd); lTime = System.currentTimeMillis() - lTime; int r = sStatement.getUpdateCount(); if (r == -1) { formatResultSet(sStatement.getResultSet()); } else { g[0] = "update count"; gResult.setHead(g); g[0] = String.valueOf(r); gResult.addRow(g); } addToRecent(txtCommand.getText()); } catch (SQLException e) { lTime = System.currentTimeMillis() - lTime; g[0] = "SQL Error"; gResult.setHead(g); String s = e.getMessage(); s += " / Error Code: " + e.getErrorCode(); s += " / State: " + e.getSQLState(); g[0] = s; gResult.addRow(g); } updateResult(); System.gc(); }
public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); if (b == bu) { j14 = new JLabel("NEW IMAGE"); j14.setBounds(840, 200, 300, 300); q.add(j14); JFileChooser filechooser = new JFileChooser(); int result = filechooser.showOpenDialog(this); f = filechooser.getSelectedFile(); try { String dir1 = f.getAbsolutePath(); // setText(dir); str = dir1; // ResizeImage.resize(dir); f = new File(dir1); } catch (Exception e1) { } repaint(); // b=(JButton)e.getSource(); } if (b == ba) { try { read(); patient.add(tadd.getText(), tsym.getText(), f, str); JOptionPane.showMessageDialog(null, "Patient ID: " + patient.pid + " Record Added"); } catch (Exception e4) { System.out.println("" + e4); } } if (b == bm) { try { setVisible(false); } catch (Exception e4) { System.out.println("" + e4); } } }
/** Method declaration */ void testPerformance() { String all = txtCommand.getText(); StringBuffer b = new StringBuffer(); long total = 0; for (int i = 0; i < all.length(); i++) { char c = all.charAt(i); if (c != '\n') { b.append(c); } } all = b.toString(); String g[] = new String[4]; g[0] = "ms"; g[1] = "count"; g[2] = "sql"; g[3] = "error"; gResult.setHead(g); int max = 1; lTime = System.currentTimeMillis() - lTime; while (!all.equals("")) { int i = all.indexOf(';'); String sql; if (i != -1) { sql = all.substring(0, i); all = all.substring(i + 1); } else { sql = all; all = ""; } if (sql.startsWith("--#")) { max = Integer.parseInt(sql.substring(3)); continue; } else if (sql.startsWith("--")) { continue; } g[2] = sql; long l = 0; try { l = DatabaseManagerCommon.testStatement(sStatement, sql, max); total += l; g[0] = String.valueOf(l); g[1] = String.valueOf(max); g[3] = ""; } catch (SQLException e) { g[0] = g[1] = "n/a"; g[3] = e.toString(); } gResult.addRow(g); System.out.println(l + " ms : " + sql); } g[0] = "" + total; g[1] = "total"; g[2] = ""; gResult.addRow(g); lTime = System.currentTimeMillis() - lTime; updateResult(); }
/** * Method declaration * * @param ev */ public void actionPerformed(ActionEvent ev) { String s = ev.getActionCommand(); if (s == null) { if (ev.getSource() instanceof MenuItem) { MenuItem i; s = ((MenuItem) ev.getSource()).getLabel(); } } if (s.equals("Execute")) { execute(); } else if (s.equals("Exit")) { windowClosing(null); } else if (s.equals("Transfer")) { Transfer.work(null); } else if (s.equals("Dump")) { Transfer.work(new String[] {"-d"}); /* NB - 26052002 Restore is not implemented yet in the transfer tool */ /* } else if (s.equals("Restore")) { Transfer.work(new String[]{"-r"}); */ } else if (s.equals("Logging on")) { jdbcSystem.setLogToSystem(true); } else if (s.equals("Logging off")) { jdbcSystem.setLogToSystem(false); } else if (s.equals("Refresh Tree")) { refreshTree(); } else if (s.startsWith("#")) { int i = Integer.parseInt(s.substring(1)); txtCommand.setText(sRecent[i]); } else if (s.equals("Connect...")) { connect(ConnectionDialog.createConnection(fMain, "Connect")); refreshTree(); } else if (s.equals("Results in Grid")) { iResult = 0; pResult.removeAll(); pResult.add("Center", gResult); pResult.doLayout(); } else if (s.equals("Open Script...")) { FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setDirectory(defDirectory); } f.show(); String file = f.getFile(); if (file != null) { txtCommand.setText(DatabaseManagerCommon.readFile(f.getDirectory() + file)); } } else if (s.equals("Save Script...")) { FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setDirectory(defDirectory); } f.show(); String file = f.getFile(); if (file != null) { DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText()); } } else if (s.equals("Save Result...")) { FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setDirectory(defDirectory); } f.show(); String file = f.getFile(); if (file != null) { showResultInText(); DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText()); } } else if (s.equals("Results in Text")) { iResult = 1; pResult.removeAll(); pResult.add("Center", txtResult); pResult.doLayout(); showResultInText(); } else if (s.equals("AutoCommit on")) { try { cConn.setAutoCommit(true); } catch (SQLException e) { } } else if (s.equals("AutoCommit off")) { try { cConn.setAutoCommit(false); } catch (SQLException e) { } } else if (s.equals("Enlarge Tree")) { Dimension d = tTree.getMinimumSize(); d.width += 20; tTree.setMinimumSize(d); fMain.pack(); } else if (s.equals("Shrink Tree")) { Dimension d = tTree.getMinimumSize(); d.width -= 20; if (d.width >= 0) { tTree.setMinimumSize(d); } fMain.pack(); } else if (s.equals("Enlarge Command")) { txtCommand.setRows(txtCommand.getRows() + 1); fMain.pack(); } else if (s.equals("Shrink Command")) { int i = txtCommand.getRows() - 1; txtCommand.setRows(i < 1 ? 1 : i); fMain.pack(); } else if (s.equals("Commit")) { try { cConn.commit(); } catch (SQLException e) { } } else if (s.equals("Insert test data")) { insertTestData(); } else if (s.equals("Rollback")) { try { cConn.rollback(); } catch (SQLException e) { } } else if (s.equals("Disable MaxRows")) { try { sStatement.setMaxRows(0); } catch (SQLException e) { } } else if (s.equals("Set MaxRows to 100")) { try { sStatement.setMaxRows(100); } catch (SQLException e) { } } else if (s.equals("SELECT")) { showHelp(DatabaseManagerCommon.selectHelp); } else if (s.equals("INSERT")) { showHelp(DatabaseManagerCommon.insertHelp); } else if (s.equals("UPDATE")) { showHelp(DatabaseManagerCommon.updateHelp); } else if (s.equals("DELETE")) { showHelp(DatabaseManagerCommon.deleteHelp); } else if (s.equals("CREATE TABLE")) { showHelp(DatabaseManagerCommon.createTableHelp); } else if (s.equals("DROP TABLE")) { showHelp(DatabaseManagerCommon.dropTableHelp); } else if (s.equals("CREATE INDEX")) { showHelp(DatabaseManagerCommon.createIndexHelp); } else if (s.equals("DROP INDEX")) { showHelp(DatabaseManagerCommon.dropIndexHelp); } else if (s.equals("CHECKPOINT")) { showHelp(DatabaseManagerCommon.checkpointHelp); } else if (s.equals("SCRIPT")) { showHelp(DatabaseManagerCommon.scriptHelp); } else if (s.equals("SHUTDOWN")) { showHelp(DatabaseManagerCommon.shutdownHelp); } else if (s.equals("SET")) { showHelp(DatabaseManagerCommon.setHelp); } else if (s.equals("Test Script")) { showHelp(DatabaseManagerCommon.testHelp); } }
public void read() { try { // patient.dt=""+tdt.getText(); patient.pid = Integer.parseInt(tpid.getText()); patient.pfnm = tpfnm.getText(); patient.pmnm = tpmnm.getText(); patient.plnm = tplnm.getText(); patient.gen = cbg.getSelectedCheckbox().getLabel(); try { patient.age = Integer.parseInt(tage.getText()); tage.setText("" + patient.age); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Invalid age inputed."); patient.age = Integer.parseInt(JOptionPane.showInputDialog("Please enter valid age:")); tage.setText("" + patient.age); } try { int wet = Integer.parseInt(twt.getText()); twt.setText("" + wet); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Invalid weight inputed."); int wet = Integer.parseInt(JOptionPane.showInputDialog("Please enter valid weight:")); twt.setText("" + wet); } patient.wt = twt.getText(); patient.addr = tadd.getText(); this.ad = tadd.getText(); System.out.println(tadd.getText()); while (true) { patient.cno = tcno.getText(); if (patient.cno.length() == 10) break; else { JOptionPane.showMessageDialog(null, "Invalid Phone No."); patient.cno = JOptionPane.showInputDialog("Please enter valid 10-digit Phone No.:"); tcno.setText(patient.cno); } } patient.dnm = tdnm.getText(); patient.sym = tsym.getText(); System.out.println(tsym.getText()); patient.dig = tdig.getText(); try { patient.fee = Integer.parseInt(tfee.getText()); tfee.setText("" + patient.fee); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Invalid Fee inputed."); patient.fee = Integer.parseInt(JOptionPane.showInputDialog("Please enter valid Fee:")); tfee.setText("" + patient.fee); } patient.bg = tbg.getText(); patient.path = str; } catch (Exception e) { } }
public patientAdd(String s) { super(s); image = new JLabel() { public void paint(Graphics g) { ImageIcon ic = new ImageIcon(str); Image img = ic.getImage(); g.drawImage(img, 0, 0, 150, 150, this); } }; image.setBounds(670, 270, 300, 300); bu = new JButton("UPLOAD"); bu.setBounds(700, 230, 100, 20); bu.addActionListener(this); // q.add(bu); ldt = new JLabel("Date"); lpid = new JLabel("Patient ID"); lpnm = new JLabel("Patient Name"); lgen = new JLabel("Gender"); lbg = new JLabel("Blood Group"); lage = new JLabel("Age"); lwt = new JLabel("Weight Kg"); ladd = new JLabel("Address"); lcno = new JLabel("Cont. no."); ldnm = new JLabel("Doctor Name Dr."); lsym = new JLabel("Symptoms"); ldig = new JLabel("Diagnosis"); lfee = new JLabel("Fee Rs."); cbg = new CheckboxGroup(); cm = new Checkbox("Male", cbg, false); cm.addItemListener(this); cf = new Checkbox("Female", cbg, false); cf.setState(true); cf.addItemListener(this); tdt = new JTextField(15); tpid = new JTextField(6); tpid.addFocusListener(this); tpfnm = new JTextField("first"); tpmnm = new JTextField("middle"); tplnm = new JTextField("last"); tage = new JTextField(4); tage.addFocusListener(this); tbg = new JTextField(6); twt = new JTextField(5); tadd = new TextArea(patient.addr); tcno = new JTextField(20); tdnm = new JTextField(20); tsym = new TextArea(); tdig = new JTextField(20); tfee = new JTextField(6); tfee.addFocusListener(this); ba = new JButton("ADD"); ba.addActionListener(this); bm = new JButton("CANCEL"); bm.addActionListener(this); bd = new JButton("DELETE"); bd.addActionListener(this); bl = new JButton("DISPLAY"); bl.addActionListener(this); bs = new JButton("SEARCH"); bs.addActionListener(this); JPanel p = new JPanel(); p.add(ba); p.add(bm); // p.add(bd); // p.add(bl); // p.add(bs); add(p, BorderLayout.SOUTH); q = new JPanel(); q.setLayout(null); ldt.setBounds(1015, 20, 60, 20); q.add(ldt); tdt.setBounds(1060, 20, 170, 20); q.add(tdt); lpid.setBounds(70, 60, 80, 20); q.add(lpid); tpid.setBounds(200, 60, 60, 20); q.add(tpid); lpnm.setBounds(70, 100, 80, 20); q.add(lpnm); tpfnm.setBounds(200, 100, 100, 20); q.add(tpfnm); tpmnm.setBounds(320, 100, 100, 20); q.add(tpmnm); tplnm.setBounds(440, 100, 100, 20); q.add(tplnm); lgen.setBounds(70, 140, 60, 20); q.add(lgen); lbg.setBounds(370, 140, 80, 20); q.add(lbg); tbg.setBounds(470, 140, 60, 20); q.add(tbg); cm.setBounds(200, 140, 60, 20); cf.setBounds(280, 140, 60, 20); lage.setBounds(70, 180, 40, 20); q.add(lage); tage.setBounds(200, 180, 50, 20); q.add(tage); lwt.setBounds(370, 180, 200, 20); q.add(lwt); twt.setBounds(470, 180, 60, 20); q.add(twt); ladd.setBounds(70, 220, 60, 20); q.add(ladd); tadd.setBounds(200, 220, 350, 50); q.add(tadd); lcno.setBounds(70, 310, 60, 20); q.add(lcno); tcno.setBounds(200, 310, 120, 20); q.add(tcno); ldnm.setBounds(70, 350, 200, 20); q.add(ldnm); tdnm.setBounds(200, 350, 150, 20); q.add(tdnm); lsym.setBounds(70, 390, 100, 20); q.add(lsym); tsym.setBounds(200, 390, 300, 70); q.add(tsym); ldig.setBounds(70, 480, 60, 20); q.add(ldig); tdig.setBounds(200, 480, 100, 20); q.add(tdig); lfee.setBounds(70, 520, 200, 20); q.add(lfee); tfee.setBounds(200, 520, 40, 20); q.add(tfee); q.add(cm); q.add(cf); q.add(image); q.add(bu); add(q, BorderLayout.CENTER); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { try { patient.con.close(); System.exit(0); } catch (Exception e8) { } } }); System.out.println(tadd.getText()); setSize(1330, 740); setVisible(true); }
public void actionPerformed(ActionEvent ae) { os = a.getText(); Pattern pat = Pattern.compile("[ .]"); String ms[] = pat.split(os), v; // Get whole String from Text area in tokens form Pattern pat1 = Pattern.compile("[ ]"); String ms1[] = pat1.split(os); // for string aaray int hcode[] = {100, 102, 220, 110, 111}, ecode[] = new int[20], j, p = 0; // p for check entry & hcode=Hindi lang.code ecode=English lang. code ResultSet rs; b.setText(""); try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "student"); Statement stmt = con.createStatement(); for (i = 0; i <= ms.length; i++) { v = "'" + ms[i] + "'"; p = 0; if (p == 0) { rs = stmt.executeQuery("select hnoun from noun where enoun=" + v); while (rs.next()) { ms1[i] = (rs.getString(1)); p++; ecode[i] = 100; } } if (p == 0) { rs = stmt.executeQuery("select hhv from hv where ehv=" + v); while (rs.next()) { ms1[i] = (rs.getString(1)); p++; ecode[i] = 111; } } if (p == 0) { rs = stmt.executeQuery("select hneg from neg where eneg=" + v); while (rs.next()) { ms1[i] = (rs.getString(1)); p++; ecode[i] = 220; } } if (p == 0) { rs = stmt.executeQuery("select hverb from verb where everb=" + v); while (rs.next()) { ms1[i] = (rs.getString(1)); p++; ecode[i] = 110; } } if (p == 0) { rs = stmt.executeQuery("select hpre from pre where epre=" + v); while (rs.next()) { ms1[i] = (rs.getString(1)); p++; ecode[i] = 140; } } if (p == 0) { rs = stmt.executeQuery("select hpro from pro where epro=" + v); while (rs.next()) { ms1[i] = (rs.getString(1)); p++; ecode[i] = 102; } } if (p == 0) { rs = stmt.executeQuery("select hart from art where eart=" + v); while (rs.next()) { ms1[i] = (rs.getString(1)); p++; ecode[i] = 123; } } } con.close(); } catch (Exception e) { System.out.println(e); } for (i = 0; i < 5; i++) { for (j = 0; j < ms.length; j++) { if (hcode[i] == ecode[j]) { b.append(ms1[j] + " "); // print to hindi code wise } } } }