コード例 #1
0
ファイル: Head.java プロジェクト: thite-amol/payroll
  public void actionPerformed(ActionEvent ae) {

    try {
      if (ae.getSource() == b7) {

        rs = st.executeQuery("select count(*) from employeemaster");
        if (rs.next()) {
          t6.setText(rs.getString(1));
        }

        rs = st.executeQuery("select * from Head");
        if (rs.next()) {
          t1.setText(rs.getString(1));
          t2.setText(rs.getString(2));
          t7.setText(rs.getString(3));
          t4.setText(rs.getString(4));
          t5.setText(rs.getString(5));
          t3.setText(rs.getString(6));
        }
      } else if (ae.getSource() == b6) {
        dispose();
      }

    } catch (Exception e) {
      JOptionPane.showMessageDialog(this, "Error is" + e);
    }
  }
コード例 #2
0
  public ExptLocatorTree(Genome g) {
    super();
    try {
      java.sql.Connection c = DatabaseFactory.getConnection(ExptLocator.dbRole);
      int species = g.getSpeciesDBID();
      int genome = g.getDBID();

      Statement s = c.createStatement();
      ResultSet rs = null;

      rs =
          s.executeQuery(
              "select e.name, e.version from experiment e, exptToGenome eg where e.active=1 and "
                  + "e.id=eg.experiment and eg.genome="
                  + genome);
      while (rs.next()) {
        String name = rs.getString(1);
        String version = rs.getString(2);
        ChipChipLocator loc = new ChipChipLocator(g, name, version);
        this.addElement(loc.getTreeAddr(), loc);
      }
      rs.close();

      rs =
          s.executeQuery(
              "select ra.name, ra.version from rosettaanalysis ra, rosettaToGenome rg where "
                  + "ra.id = rg.analysis and ra.active=1 and rg.genome="
                  + genome);
      while (rs.next()) {
        String name = rs.getString(1);
        String version = rs.getString(2);
        MSPLocator msp = new MSPLocator(g, name, version);
        this.addElement(msp.getTreeAddr(), msp);
      }
      rs.close();

      rs =
          s.executeQuery(
              "select ra.name, ra.version from bayesanalysis ra, bayesToGenome rg where "
                  + "ra.id = rg.analysis and ra.active=1 and rg.genome="
                  + genome);
      while (rs.next()) {
        String name2 = rs.getString(1);
        String version2 = rs.getString(2);
        ExptLocator loc2 = new BayesLocator(g, name2, version2);
        addElement(loc2.getTreeAddr(), loc2);
      }
      rs.close();
      s.close();

      DatabaseFactory.freeConnection(c);
    } catch (SQLException se) {
      se.printStackTrace(System.err);
      throw new RuntimeException(se);
    } catch (UnknownRoleException e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
ファイル: TestThread.java プロジェクト: openlink/jdbc-bench
 public void run() {
   m_nTrans = 0;
   m_nTrans1Sec = 0;
   m_nTrans2Sec = 0;
   m_nTimeSum = 0;
   if (m_nNumRuns <= 0) return;
   Statement stmt = null;
   try {
     stmt = m_conn.createStatement();
     ResultSet set;
     // get branch count
     log("select max(branch) from " + m_Driver.getBranchName() + "\n", 2);
     set = stmt.executeQuery("select max(branch) from " + m_Driver.getBranchName());
     if (set != null && set.next()) {
       m_nMaxBranch = set.getInt(1);
       set.close();
     }
     // get teller count
     log("select max(teller) from " + m_Driver.getTellerName() + "\n", 2);
     set = stmt.executeQuery("select max(teller) from " + m_Driver.getTellerName());
     if (set != null && set.next()) {
       m_nMaxTeller = set.getInt(1);
       set.close();
     }
     // get account count
     log("select max(account) from " + m_Driver.getAccountName() + "\n", 2);
     set = stmt.executeQuery("select max(account) from " + m_Driver.getAccountName());
     if (set != null && set.next()) {
       m_nMaxAccount = set.getInt(1);
       set.close();
     }
   } catch (SQLException e) {
     log("Error getting table limits : " + e.getMessage() + "\n", 0);
   } finally {
     if (stmt != null)
       try {
         stmt.close();
       } catch (SQLException e) {
       }
     stmt = null;
   }
   //		System.out.println("Thread : " + getName() + " Branch :" + m_nMaxBranch + " Teller : " +
   // m_nMaxTeller + " Account : " + m_nMaxAccount);
   if (m_bRunText) runTextTest();
   if (m_bRunPrepared) runPrepareTest();
   if (m_bRunSProc) runProcTest();
   if (m_bCloseConnection) {
     try {
       m_conn.close();
       log("Thread connection closed", 2);
     } catch (SQLException e) {
     }
   }
   if (m_log != null) m_log.taskDone();
 }
コード例 #4
0
ファイル: JDBCClient.java プロジェクト: andrewburger/java
public JTable queryTable(String table, String query) {

	//create statement
	Statement stmt = con.createStatement();
	stmt.executeUpdate(table);

	//query db for table
	ResultSet rs = stmt.executeQuery(query);

	//initialize values for jtable
	Object[50][50] data;
	int n=1;
	int p=1;

	//put info into jtable
	while (rs.next()) { // print up to 50 rows

	while (n<=50) { // print up to 50 columns
		String s = rs.getString(n);
		data[p][n] = s;
		}

	n=1;
	p++;
	}

	//create jtable
	String[] columnNames = {query};
	final JTable jtable = new JTable(data, columnNames);

	return jtable;
}
コード例 #5
0
ファイル: TableDeneme.java プロジェクト: herlixjae/tubes1
  public void setQuery(String q) {
    cache = new Vector();
    try {
      ResultSet rs = statement.executeQuery(q);
      ResultSetMetaData meta = rs.getMetaData();
      colCount = meta.getColumnCount();
      headers = new String[colCount];
      for (int h = 1; h <= colCount; h++) {
        headers[h - 1] = meta.getColumnName(h);
      }
      while (rs.next()) {
        String[] record = new String[colCount];
        for (int i = 0; i < colCount; i++) {
          record[i] = rs.getString(i + 1);
        }
        cache.addElement(record);
      } // while sonu

      fireTableChanged(null);
    } // try sonu
    catch (Exception e) {
      cache = new Vector();
      e.printStackTrace();
    }
  } // setQuery sonu
コード例 #6
0
ファイル: TestThread.java プロジェクト: openlink/jdbc-bench
 public void executeQuery() throws SQLException {
   log(
       "select account, branch, balance, filler from "
           + m_Driver.getAccountName()
           + " where account < 101\n",
       2);
   Statement stmt = null;
   try {
     stmt = m_conn.createStatement();
     ResultSet set =
         stmt.executeQuery(
             "select account, branch, balance, filler from "
                 + m_Driver.getAccountName()
                 + " where account < 101");
     while (set.next()) {
       set.getInt(1);
       set.getInt(2);
       set.getDouble(3);
       set.getString(4);
     }
     set.close();
   } finally {
     if (stmt != null) stmt.close();
     stmt = null;
   }
 }
コード例 #7
0
    public void actionPerformed(ActionEvent ae) {
      try {

        Integer num = Integer.parseInt(tfdid.getText());
        String name;
        String addr;
        String contact;
        String spec;
        String workf;
        String workt;

        Statement st = cn.createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM DOC WHERE did=" + num);

        if (rs.next()) {
          num = rs.getInt("did");
          name = rs.getString("name");
          addr = rs.getString("address");
          contact = rs.getString("contact");
          spec = rs.getString("specialization");
          workf = rs.getString("workfrom");
          workt = rs.getString("workto");

          tfname.setText(name);
          taadd.setText(addr);
          tftel.setText(contact);
          taspecial.setText(spec);
          tfworkf.setText(workf);
          tfworkt.setText(workt);
        }

      } catch (SQLException sq) {
        System.out.println(sq);
      }
    }
コード例 #8
0
ファイル: data_Lembur.java プロジェクト: muhlik/overtimeapps
  private void Simpan() {

    if (btnSave.getText().equals("Edit")) {
      try {
        Class.forName(KoneksiDatabase.driver);
        java.sql.Connection c =
            DriverManager.getConnection(
                KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass);
        Statement s = c.createStatement();

        String sql;
        sql = "update absensi_lembur set tipehari = '";
        sql += cmbJenisHari.getSelectedItem() + "', tot_waktu_lembur='";
        sql += txtTotalLembur.getText() + "'";
        sql += "where kd_absen = '" + txtKodeAbsen.getText() + "'";
        s.executeQuery(sql);

        JOptionPane.showMessageDialog(
            null, "Data Berhasil Disimpan!!!", "Informasi", JOptionPane.INFORMATION_MESSAGE);
      } catch (Exception e) {
        JOptionPane.showMessageDialog(
            null,
            "Gagal Disimpan, Data Harus Lengkap !!!",
            "Peringatan",
            JOptionPane.WARNING_MESSAGE);
      }
    }
    Baru();
  }
コード例 #9
0
  public void actionPerformed(java.awt.event.ActionEvent evt) {
    String sql1 =
        "select a.* FROM ANTENA a WHERE a.ID_antena='"
            + (newJPanel.jList1.getSelectedIndex() + 1)
            + "' ";
    String pom = "";
    System.out.println(sql1);
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver");
      Connection conn;
      try {
        conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", user, password);

        Statement stmt1 = conn.createStatement();
        ResultSet rs1 = stmt1.executeQuery(sql1);
        while (rs1.next()) {
          NewJPanel.jTextField1.setText(rs1.getString("ID_antena"));
          NewJPanel.jTextField2.setText(rs1.getString("Producent"));
          NewJPanel.jTextField3.setText(rs1.getString("Numer_identyfikacyjny"));
          NewJPanel.jTextField4.setText(rs1.getString("Czestotliwosc"));
          NewJPanel.jTextField5.setText(rs1.getString("Polaryzacja"));
          NewJPanel.jTextField6.setText(rs1.getString("Moc"));
          NewJPanel.jTextField7.setText(rs1.getString("Rodzaj"));
        }
      } catch (SQLException e1) {
        System.out.println("tutaj 1");
        e1.printStackTrace();
      }
    } catch (ClassNotFoundException e1) {
      System.out.println("tutaj 2");
      e1.printStackTrace();
    }
  }
コード例 #10
0
 private void ListValueChanged(
     javax.swing.event.ListSelectionEvent evt) { // GEN-FIRST:event_ListValueChanged
   // TODO add your handling code here:
   // String part=partno.getText();
   try {
     String sql =
         "SELECT  TYPE,ITEM_NAME,QUANTITY,MRP FROM MOTORS WHERE ITEM_NAME='"
             + List.getSelectedValue()
             + "'";
     Class.forName("com.mysql.jdbc.Driver");
     Connection con =
         (Connection)
             DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", "");
     Statement stmt = con.createStatement();
     ResultSet rs = stmt.executeQuery(sql);
     while (rs.next()) {
       partno.setText(rs.getString("TYPE"));
       name.setText(rs.getString("ITEM_NAME"));
       qty.setText(rs.getString("QUANTITY"));
       rate.setText(rs.getString("MRP"));
     }
   } catch (Exception e) {
     JOptionPane.showMessageDialog(null, e.toString());
   }
 } // GEN-LAST:event_ListValueChanged
コード例 #11
0
ファイル: AddEditForm.java プロジェクト: robpuff/2761Login
  private void isEdit(Boolean isEdit) {
    if (isEdit) {
      try {
        Connection con = FrameLogin.getConnect();
        String sql = "SELECT * FROM Persons WHERE personId = " + Id;
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
        if (rs.first()) {
          String firstname = rs.getString("FirstName");
          String lastname = rs.getString("LastName");
          String cellphone = rs.getString("CellPhoneNo");
          String homephone = rs.getString("HomePhoneNo");
          String gradyear = rs.getString("Graduation Year");
          String Gender = rs.getString("Gender");

          firstName.setText(firstname);
          lastName.setText(lastname);
          cellPhone.setText(cellphone);
          homePhone.setText(homephone);
          gradYear.setText(gradyear);
          gender.setSelectedItem(Gender);
          jLabel7.setVisible(false);
          studentId.setVisible(false);

        } else {
          MessageBox.infoBox("Error: ID not found", "Error");
        }
      } catch (Exception e) {
        MessageBox.infoBox(e.toString(), "Error in isEdit");
      }
    }
    FrameLogin.closeConnect();
  }
コード例 #12
0
 public Insert(java.awt.Frame parent, boolean modal, Connection cn, String h) {
   super(parent, modal);
   initComponents();
   con = cn;
   jPanel1.setBounds(0, 0, 800, 1000);
   s = h;
   try {
     Statement st = con.createStatement();
     ResultSet rs1 = st.executeQuery("select * from " + s);
     ResultSetMetaData rd = rs1.getMetaData();
     count = rd.getColumnCount();
     if (count >= 5) jPanel1.setLayout(new java.awt.GridLayout(count, 5, 20, 20));
     else jPanel1.setLayout(new java.awt.GridLayout(count, 5, 40, 40));
     l = new JLabel[count];
     l2 = new JLabel[count];
     l1 = new JLabel[count];
     t = new JTextField[count];
     jLabel1.setText("INSERT INTO " + s);
     getContentPane().add(jLabel1, BorderLayout.NORTH);
     for (i = 1; i <= count; i++) {
       if (rd.isNullable(i) == ResultSetMetaData.columnNoNulls) l2[i - 1] = new JLabel("Not Null");
       else l2[i - 1] = new JLabel("Nullable");
       l[i - 1] = new JLabel(rd.getColumnName(i));
       jPanel1.add(l[i - 1]);
       l1[i - 1] = new JLabel("(" + rd.getColumnTypeName(i) + ")");
       jPanel1.add(l1[i - 1]);
       jPanel1.add(l2[i - 1]);
       t[i - 1] = new JTextField();
       jPanel1.add(t[i - 1]);
     }
   } catch (Exception e) {
     System.out.println(e);
   }
 }
コード例 #13
0
ファイル: data_Lembur.java プロジェクト: muhlik/overtimeapps
  private void Baru() {
    btnSave.setText("Save");
    txtNip.requestFocus();
    txtNip.setText("");

    try {
      Class.forName(KoneksiDatabase.driver);
      java.sql.Connection c =
          DriverManager.getConnection(
              KoneksiDatabase.database, KoneksiDatabase.user, KoneksiDatabase.pass);
      Statement s = c.createStatement();
      String sql = "select * from absensi_lembur";
      ResultSet rs = s.executeQuery(sql);

      final String[] headers = {
        "Kd Absen",
        "NIP",
        "Tgl Absen",
        "Masuk",
        "Pulang",
        "Hari",
        "Tipe Hari",
        "Terlambat",
        "Lembur",
        "Tipe Lembur",
        "Tot Lembur",
        "Tunj Makan",
        "Tunj Transport"
      };
      rs.last();

      int n = rs.getRow();
      Object[][] data = new Object[n][13];
      int p = 0;
      rs.beforeFirst();
      while (rs.next()) {
        data[p][0] = rs.getString(1);
        data[p][1] = rs.getString(2);
        data[p][2] = rs.getString(3);
        data[p][3] = rs.getString(4);
        data[p][4] = rs.getString(5);
        data[p][5] = rs.getString(6);
        data[p][6] = rs.getString(7);
        data[p][7] = rs.getString(8);
        data[p][8] = rs.getString(9);
        data[p][9] = rs.getString(10);
        data[p][10] = rs.getString(11);
        data[p][11] = rs.getString(12);
        data[p][12] = rs.getString(13);
        p++;
      }
      tblLembur.setModel(new DefaultTableModel(data, headers));
      tblLembur.setAlignmentX(CENTER_ALIGNMENT);

    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          null, "Gagal Koneksi, Ada Kesalahan.", "Warning", JOptionPane.WARNING_MESSAGE);
    }
  }
コード例 #14
0
  private void jButton3ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton3ActionPerformed
    try {
      Connection con =
          (Connection)
              DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", "");
      Statement stmt = con.createStatement();

      ResultSet resultSet = stmt.executeQuery("select Bill_No from bill;");

      String productCode = null;

      while (resultSet.next()) {
        productCode = resultSet.getString("Bill_No");
      }
      int pc = Integer.parseInt(productCode);
      System.out.println(pc);
      no.setText((String.valueOf(++pc)));
      // TODO add your handling code here:

      String part = partno.getText();
      String itemname = name.getText();
      String qty1 = qty.getText();
      String rate1 = rate.getText();
      // String amo=amount.getText();
      String noo = no.getText();
      no1 = Integer.parseInt(noo);
      cname = custname.getText();
      bill1 = bill.getText();
      addr1 = addr.getText();

      String ta = tax.getText();
      int a = Integer.parseInt(qty1);
      int b = Integer.parseInt(rate1);
      int c = a * b;
      String str = Integer.toString(c);
      amount.setText(str);
      String str1 = amount.getText();
      /* String sql1="select Quantity from lubricants";
      String sql2="UPDATE LUBRICANTS SET QUANTITY=QUANTITY-qty1 WHERE PART_NO='"+partno+"'";
      Statement stmt1=con.createStatement();
      ResultSet rs1= stmt1.executeQuery(sql1);

      String ch=rs1.getString("QUANTITY");
      int q=Integer.parseInt(qty1);
      int r=Integer.parseInt(ch);
      if(q >r)
      {
          JOptionPane.showMessageDialog(this,"STOCK UNAVAILABLE");
      }
      else
      {
          stmt1.executeUpdate(sql2);
      }*/
    } catch (SQLException ex) {
      Logger.getLogger(Billspare.class.getName()).log(Level.SEVERE, null, ex);
    }
  } // GEN-LAST:event_jButton3ActionPerformed
コード例 #15
0
  public void connectItems(String query)
        // PRE:  query must be initialized
        // POST: Updates the list of Items based on the query.
      {
    String driver = "org.apache.derby.jdbc.ClientDriver"; // Driver for DB
    String url = "jdbc:derby://localhost:1527/ShopDataBase"; // Url for DB
    String user = "******"; // Username for db
    String pass = "******"; // Password for db
    Connection myConnection; // Connection obj to db
    Statement stmt; // Statement to execute a result appon
    ResultSet results; // A set containing the returned results
    int rowcount; // Num objects in the resultSet
    int i; // Index for the array

    try { // Try connection to db

      Class.forName(driver).newInstance(); // Create our db driver

      myConnection = DriverManager.getConnection(url, user, pass); // Initalize our connection

      stmt =
          myConnection.createStatement(
              ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_UPDATABLE); // Create a new statement
      results = stmt.executeQuery(query); // Store the results of our query

      rowcount = 0;
      if (results.last()) // Go to the last result
      {
        rowcount = results.getRow();
        results.beforeFirst();
      }
      itemsArray = new Item[rowcount];

      i = 0;
      while (results.next()) // Itterate through the results set
      {
        itemsArray[i] =
            new Item(
                results.getInt("item_id"),
                results.getString("item_name"),
                results.getString("item_type"),
                results.getInt("price"),
                results.getInt("owner_id"),
                results.getString("item_path")); // Creat new Item
        i++;
      }

      results.close(); // Close the ResultSet
      stmt.close(); // Close the statement
      myConnection.close(); // Close the connection to db

    } catch (Exception e) // Cannot connect to db
    {
      System.err.println(e.toString());
      System.err.println("Error, something went horribly wrong in connectItems!");
    }
  }
コード例 #16
0
ファイル: AdminLogin.java プロジェクト: danteata/sms
 private void passwordTextBoxKeyPressed(
     java.awt.event.KeyEvent evt) { // GEN-FIRST:event_passwordTextBoxKeyPressed
   // TODO add your handling code here:
   int key = evt.getKeyCode();
   if (key == KeyEvent.VK_ENTER) {
     boolean verify = false;
     String user = usernameTextBox.getText();
     String passwd = passwordTextBox.getText();
     if (user.equals("") || passwd.equals("")) {
       JOptionPane.showMessageDialog(
           AdminLogin.this, "Sorry! You must enter a Username and Password to login ");
       usernameTextBox.requestFocus();
     } else {
       Connection con = getConnection();
       try {
         ResultSet rows;
         Statement s =
             con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
         String select = "Select * from admin;";
         rows = s.executeQuery(select);
         while (rows.next()) {
           String username = rows.getString("Username");
           String password = rows.getString("Password");
           if (user.equals(username) && passwd.equals(password)) {
             verify = true;
             this.dispose();
             //                       btn.btnEnabled();
             break;
           }
         }
         if (verify == false) {
           verify = false;
           JOptionPane.showMessageDialog(
               AdminLogin.this, "Access Denied! Invalid Username or Password");
           usernameTextBox.setText("");
           passwordTextBox.setText("");
           usernameTextBox.requestFocus();
         }
       } catch (SQLException e) {
         System.out.println(e.getMessage());
       }
       if (verify == false) {
         JOptionPane.showMessageDialog(
             AdminLogin.this, "Access Denied!  Invalid Username or Password");
         usernameTextBox.setText("");
         passwordTextBox.setText("");
         usernameTextBox.requestFocus();
       } // TODO add your handling code here:
     }
   }
   if (key == KeyEvent.VK_UP) {
     usernameTextBox.grabFocus();
   }
   if (key == KeyEvent.VK_KP_UP) {
     usernameTextBox.grabFocus();
   }
 } // GEN-LAST:event_passwordTextBoxKeyPressed
コード例 #17
0
ファイル: username.java プロジェクト: anuj1708/Practice
  public static void goer() throws Exception {

    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con =
        (Connection) DriverManager.getConnection("jdbc:oracle:thin:@localhost", "system", "system");
    String query2 = "select * from logger";
    Statement st2 = con.createStatement();
    ResultSet rs = st2.executeQuery(query2);
    boolean b = false;
    while (rs.next()) {
      if ((rs.getString(3)).equals(p2.str3)) {
        b = true;
      }
    }
    if (b == false) {
      String query1 =
          "insert into logger values('"
              + p2.str1
              + "','"
              + p2.str2
              + "','"
              + p2.str3
              + "','"
              + p2.str4
              + "','"
              + p2.str5
              + "','"
              + p2.str7
              + "','"
              + p2.str8
              + "','"
              + p2.str9
              + "','"
              + p2.str13
              + "')";
      Statement st1 = con.createStatement();
      st1.executeQuery(query1);
      JOptionPane.showMessageDialog(null, "welcome\n now you are a meber of our team ");
    } else {
      JOptionPane.showMessageDialog(null, "this username already exist");
    }
  }
コード例 #18
0
ファイル: LoginScreen.java プロジェクト: vooratarun/javasis
 public boolean isValidUser() throws SQLException {
   CreateJDBCConnection jdbc = new CreateJDBCConnection();
   Statement stmt = jdbc.getStatement();
   stmt.execute("use jana;");
   String sqlQuery =
       "select password from user_details where idno = '" + nameText.getText() + "';";
   ResultSet rs = stmt.executeQuery(sqlQuery);
   while (rs.next()) {
     if (rs.getString("password").equals(passText.getText())) return true;
   }
   return false;
 }
コード例 #19
0
  public void updateTables(String updateQuery1, String updateQuery2, String updateQuery3)
        // PRE:  updateQuery1,updateQuery2, updateQuery3 must be initialized
        // POST: Updates the list of Items based on the querys.
      {
    String driver = "org.apache.derby.jdbc.ClientDriver"; // Driver for DB
    String url = "jdbc:derby://localhost:1527/ShopDataBase"; // Url for DB
    String user = "******"; // Username for db
    String pass = "******"; // Password for db
    Connection myConnection; // Connection obj to db
    Statement stmt; // Statement to execute a result appon
    ResultSet results; // A set containing the returned results
    int i; // Index for the array
    try // Try connection to db
    {

      Class.forName(driver).newInstance(); // Create our db driver

      myConnection = DriverManager.getConnection(url, user, pass); // Initalize our connection

      stmt =
          myConnection.createStatement(
              ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
      stmt.executeUpdate(updateQuery1);

      stmt.executeUpdate(updateQuery2);

      stmt.executeUpdate(updateQuery3);

      results = stmt.executeQuery(previous_query); // Call the previous query

      i = 0;
      while (results.next()) // Itterate through the results set
      {
        itemsArray[i] =
            new Item(
                results.getInt("item_id"),
                results.getString("item_name"),
                results.getString("item_type"),
                results.getInt("price"),
                results.getInt("owner_id"),
                results.getString("item_path"));
        i++;
      }
      results.close(); // Close the ResultSet
      stmt.close(); // Close the statement
      myConnection.close(); // Close the connection to db

    } catch (Exception e) // Cannot connect to db
    {
      System.err.println(e.toString());
      System.err.println("Error, something went horribly wrong! in updateTables");
    }
  }
コード例 #20
0
  public void updateRecord() {
    String totalSeat, alotSeat, vacentSeat, strHostel;
    try {
      rs = statement.executeQuery("select hostelName from hostelStatus");
      while (rs.next()) {
        strHostel = rs.getString(1);

        try {
          rs1 = statement1.executeQuery("select count(*) from " + strHostel + "");
          rs1.next();
          totalSeat = rs1.getString(1);

          rs1 = statement1.executeQuery("select count(*) from " + strHostel + " where status='F'");
          rs1.next();
          alotSeat = rs1.getString(1);

          try {
            vacentSeat = String.valueOf(Integer.parseInt(totalSeat) - Integer.parseInt(alotSeat));
            statement1.executeUpdate(
                "update hostelStatus set totalSeat='"
                    + totalSeat
                    + "',vacentSeat='"
                    + vacentSeat
                    + "'where hostelName='"
                    + strHostel
                    + "'");
            statement1.executeUpdate("commit");
            rs1.close();
          } catch (SQLException sqle) {
            JOptionPane.showMessageDialog(null, sqle);
          }

        } catch (SQLException sqle) {
          JOptionPane.showMessageDialog(null, "Error " + sqle);
        }
      }
    } catch (SQLException sq) {
      JOptionPane.showMessageDialog(null, sq);
    }
  }
コード例 #21
0
  public void actionPerformed(ActionEvent ae) {
    String str = ae.getActionCommand();
    if (str.equals("Ok")) {
      String str1 = (String) jcmname.getSelectedItem();

      Connection con = null;
      Statement stat = null;

      if (str1.equals("Pulsar")
          || str1.equals("CT 100")
          || str1.equals("Discover DTS-i")
          || str1.equals("Wave DTS-i")) {
        try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          con = DriverManager.getConnection("Jdbc:Odbc:showroom");
          System.out.println("Got Connection :" + con);
          stat = con.createStatement();
          ResultSet rs = stat.executeQuery("select * from vehicle");
          System.out.println("chk1");
          while (rs.next()) {
            if (str1.equals(rs.getString(1))) {

              tfcap.setText("" + rs.getInt(2));
              tfeng.setText("" + rs.getInt(3));
              tfbhp.setText("" + rs.getInt(4));
              tfvolt.setText("" + rs.getInt(5));
              tfrpm.setText("" + rs.getInt(6));
              tfweight.setText("" + rs.getInt(7));
              tfgear.setText("" + rs.getInt(8));
            }
          }

          stat.close();
          con.close();

        } catch (Exception ex) {
        }

      } else {
        JOptionPane.showMessageDialog(
            null, "Please Choose Model Name", "Error", JOptionPane.ERROR_MESSAGE);
      }
    }

    if (str.equals("can")) {
      this.dispose();
      // new menu(1);
    }
  }
コード例 #22
0
  public SingleNameReport(WritableWorkbook workbook, Statement new_statement, String[] arguments) {

    String main_tsn = "";
    String main_rank = "";
    String main_kingdom = "";
    row = 0;
    try {
      statement = new_statement;
      func = new AdditionalFunctions(statement);
      copy = workbook;
      kingdom = arguments[0];
      hrank = arguments[1];
      lrank = arguments[2];
      scientificName = arguments[3];
      date_from = arguments[4];
      date_to = arguments[5];
      user = arguments[6];

      String temp = "";
      temp =
          "SELECT tsn,rank_id,kingdom_id from Tree where scientificName='" + scientificName + "'";
      System.out.println(temp);
      result = statement.executeQuery(temp);
      metadata = result.getMetaData();
      int numberOfRows = 0;
      int hrankVal = Integer.parseInt(hrank);
      int main_rankVal = 0;
      if (result.last()) numberOfRows = result.getRow();
      result.first();
      if (numberOfRows > 0 && metadata.getColumnCount() > 0) {
        main_tsn = result.getString(1);
        main_rank = result.getString(2);
        main_rankVal = Integer.parseInt(main_rank);
        main_kingdom = result.getString(3);
      }
      if (HasChildren(main_tsn) == true) FindChildInformation(main_tsn, arguments, func);

      FileInFrontPage frontPage = new FileInFrontPage(copy, statement, arguments);
      copy.write();
      copy.close();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  } // end of constructor
コード例 #23
0
  /**
   * Fill the table using m_sql
   *
   * @param table table
   */
  private static void tableLoad(MiniTable table) {
    //	log.finest(m_sql + " - " +  m_groupBy);
    String sql =
        MRole.getDefault()
                .addAccessSQL(m_sql.toString(), "tab", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO)
            + m_groupBy
            + m_orderBy;

    log.finest(sql);
    try {
      Statement stmt = DB.createStatement();
      ResultSet rs = stmt.executeQuery(sql);
      table.loadTable(rs);
      stmt.close();
    } catch (SQLException e) {
      log.log(Level.SEVERE, sql, e);
    }
  } //  tableLoad
コード例 #24
0
  // public method that checks for existance of children
  public boolean HasChildren(String tsn) {

    String temp = "SELECT tsn from Tree where parent_tsn='" + tsn + "'";
    if (lrank.compareTo("0") != 0 && lrank.compareTo("7") != 0)
      temp = temp + " AND rank_id<=" + lrank;
    System.out.println(temp);
    int numberOfRows = 0;
    boolean flag = false;
    try {
      result = statement.executeQuery(temp);
      metadata = result.getMetaData();
      if (result.last()) numberOfRows = result.getRow();
      result.first();
      if (numberOfRows > 0 && metadata.getColumnCount() > 0) flag = true;
    } catch (SQLException sql) {
      sql.printStackTrace();
      System.exit(1);
    }
    return flag;
  } // end of method HasChildren
コード例 #25
0
ファイル: FrameLogin.java プロジェクト: robpuff/2761Login
 private boolean isLoggedIn(int id) {
   boolean isLoggedIn = false;
   Connection con = getConnect();
   int personId = getPersonId(id);
   try {
     String SQL = "SELECT * FROM LogInOut WHERE personId = " + personId + " AND TimeOut IS NULL";
     Statement stmt = con.createStatement();
     ResultSet rs = stmt.executeQuery(SQL);
     if (rs != null && rs.next()) {
       rs.last();
       isLoggedIn = true;
     }
   } catch (Exception err) {
     MessageBox.infoBox(err.toString(), "Error from isLoggedIn");
     System.out.println(err);
   }
   closeConnect();
   return isLoggedIn;
   // SELECT * FROM LogInOut WHERE personId = 1 AND TimeOut IS NULL
 }
コード例 #26
0
ファイル: FrameLogin.java プロジェクト: robpuff/2761Login
 public static int getPersonId(int id) {
   Connection con = getConnect();
   ResultSet rs = null;
   int personId = 0;
   try {
     String SQL = "SELECT PersonId FROM 2761DB.Persons WHERE SchoolId = " + id;
     Statement stmt = con.createStatement();
     rs = stmt.executeQuery(SQL);
     if (rs.next()) {
       rs.first();
       personId = rs.getInt("PersonId");
     } else {
       AddUserQuery addUserQuery = new AddUserQuery();
       addUserQuery.setVisible(true);
     }
   } catch (Exception err) {
     MessageBox.infoBox(err.toString(), "Error in getPersonId");
   }
   closeConnect();
   return personId;
 }
コード例 #27
0
ファイル: M.java プロジェクト: saraswatendra/Login-Page
    public void actionPerformed(ActionEvent e) {
      String name4 = JOptionPane.showInputDialog("Enter the UserId:");
      String name5 = JOptionPane.showInputDialog("Enter the DOB(dd/mm/yyyy):");
      try {
        DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
        Connection con =
            DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1521:xe", "system", "9696030257");
        Statement st = con.createStatement();
        ResultSet rs =
            st.executeQuery(
                "select * from database where userid='" + name4 + "' and dob='" + name5 + "'");
        rs.next();
        String z = rs.getString("password");
        JOptionPane.showMessageDialog(null, "Your  Password  is  <  " + z + "  >");

      } catch (Exception ex) {
        System.out.print(ex);
        JOptionPane.showMessageDialog(null, "Please Enter valid UserId and DOB(dd/mm/yyyy) .");
      }
    }
コード例 #28
0
ファイル: EchoAWT.java プロジェクト: operationcwal/app
  public void login() {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:orcl";
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    String id, pw, sql;
    try {
      Class.forName(driver);
      con = DriverManager.getConnection(url, "hr", "hr");
      stmt = con.createStatement();
      sql = "select * from chatuser where id = '" + lid.getText() + "'";
      rs = stmt.executeQuery(sql);
      if (rs.next()) {
        pw = rs.getString(2);
        nick = rs.getString(3);
        if (lpw.getText().equals(pw)) {
          jd.setVisible(false);
          setVisible(true);
        } else {
          lpw.setText("일치하지 않습니다.");
        }
      } else {
        lid.setText("일치하지 않습니다.");
      }
    } catch (Exception e1) {
      e1.printStackTrace();
      System.out.println("데이터 베이스 연결 실패!!");
    } finally {
      try {
        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
        if (con != null) con.close();
      } catch (Exception e1) {
        System.out.println(e1.getMessage());
      }
    }
  }
コード例 #29
0
ファイル: FrameLogin.java プロジェクト: robpuff/2761Login
 public static boolean isIdFound(int id) {
   Connection con = getConnect();
   boolean isFound = false;
   try {
     String SQL =
         "SELECT PersonId, FirstName, LastName, SchoolId FROM 2761DB.Persons WHERE SchoolId = "
             + id;
     Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
     ResultSet rs = stmt.executeQuery(SQL);
     if (rs.first()) {
       isFound = true;
     } else {
       AddUserQuery addUser = new AddUserQuery();
       addUser.setVisible(true);
     }
   } catch (SQLException err) {
     System.out.println(err);
     MessageBox.infoBox(err.toString(), "Error");
   }
   closeConnect();
   return isFound;
 }
コード例 #30
0
  public void FillList() {
    try {

      String sql1 = "select  * from motors";
      Class.forName("com.mysql.jdbc.Driver");
      Connection con =
          (Connection)
              DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", "");
      Statement stmt = con.createStatement();
      ResultSet rs1 = stmt.executeQuery(sql1);
      DefaultListModel DLM = new DefaultListModel();

      while (rs1.next()) {
        DLM.addElement(rs1.getString(3));
        // DLM.addElement(rs1.getString(2));
      }

      List.setModel(DLM);
    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, "e.getString()");
    }
  }