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); } }
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(); }
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
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); } }
public void actionPerformed(ActionEvent e) { try { String name = JOptionPane.showInputDialog("Enter the UserId:"); String name1 = JOptionPane.showInputDialog("Enter the Password:"******"Enter the MobileNo:"); // int name2=Integer.parseInt(name22); String name3 = JOptionPane.showInputDialog("Enter the DOB(dd/mm/yyyy):"); DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); Connection con = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe", "system", "9696030257"); Statement st = con.createStatement(); st.executeUpdate( "insert into database values('" + name + "','" + name1 + "','" + name2 + "','" + name3 + "')"); st.executeUpdate("commit"); JOptionPane.showMessageDialog( null, "Hi !! Welcome in Our Database.Your userId is < " + name + " > And Password is < ******* >"); } catch (Exception ex) { System.out.print(ex); JOptionPane.showMessageDialog(null, "Please Fill All Entry OR choose another UsetId."); } }
/** 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 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!"); } }
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
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
private void submitButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_submitButtonActionPerformed // TODO add your handling code here: Connection con = FrameLogin.getConnect(); String SQLInsert = "INSERT INTO `2761DB`.`Persons` (`FirstName`, `LastName`, `CellPhoneNo`, `HomePhoneNo`, " + "`SchoolId`, `Graduation Year`, `Gender`) VALUES ('" + firstName.getText() + "', '" + lastName.getText() + "', '" + cellPhone.getText() + "', '" + homePhone.getText() + "', '" + studentId.getText() + "', '" + gradYear.getText() + "', '" + (String) (gender.getSelectedItem()) + "');"; String SQLUpdate = "UPDATE `2761DB`.`Persons` SET `FirstName` = '" + firstName.getText() + "', `LastName` = '" + lastName.getText() + "', `CellPhoneNo` = ' " + cellPhone.getText() + "', `HomePhoneNo` = '" + homePhone.getText() + "', `Graduation Year` = '" + gradYear.getText() + "', `Gender` = '" + (String) (gender.getSelectedItem()) + "' WHERE `PersonId` = '" + Id + "';"; // UPDATE `2761DB`.`Persons` SET `FirstName`='Robbie', `LastName`='Tacescu', `CellPhoneNo`='', // `HomePhoneNo`='559300', `SchoolId`='15648916', `Graduation Year`='6545', `Gender`='males' // WHERE // `PersonId`='42'; try { if (isEdit) { Statement stmt = con.createStatement(); // System.out.println(SQLUpdate); stmt.executeUpdate(SQLUpdate); } else { Statement stmt = con.createStatement(); // System.out.println(SQLInsert); stmt.executeUpdate(SQLInsert); } } catch (SQLException err) { MessageBox.infoBox(err.toString(), "Error in AddUserForm submitButton"); } FrameLogin.closeConnect(); this.dispose(); } // GEN-LAST:event_submitButtonActionPerformed
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; }
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == bRes) { tname.setText(""); textra.setText(""); } else { if (it.isSelected()) field = 1; else if (civil.isSelected()) field = 2; else if (mech.isSelected()) field = 3; if (tname.getText().equals("") | textra.getText().equals("") | field == 0) JOptionPane.showMessageDialog(null, "Please Fill in All Entries!!"); else { String sal = (String) cbsal.getSelectedItem(); try { // Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Connection conn=DriverManager.getConnection("jdbc:odbc:go"); Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:mysql:///go", "root", ""); Statement pst = conn.createStatement(); pst.executeUpdate( "Insert into company values('" + tname.getText() + "','" + textra.getText() + "','" + (String) sal + "','" + field + "','" + tusr.getText() + "','" + tpwd.getText() + "')"); conn.close(); String msg = "Your Details are Stored. Login again to View Related applicants! Thank You!!"; JOptionPane.showMessageDialog(null, msg); setVisible(false); login ab = new login(); } catch (Exception exc) { JOptionPane.showMessageDialog(null, tname.getText() + " : " + exc); System.exit(0); } } } }
private void logIn(int personId) { Connection con = getConnect(); try { // MessageBox.infoBox("You have successfully logged in", "Login"); // INSERT INTO LogInOut (PersonId, TimeIn) VALUES (1, NOW()) String SQLLogin = "******" + personId + ", NOW())"; Statement stmtLogin = con.createStatement(); stmtLogin.executeUpdate(SQLLogin); Update_table(); } catch (SQLException err) { MessageBox.infoBox(err.toString(), "Error"); } closeConnect(); }
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); } }
public void setValueAt(Object value, int row, int col) { // are you editing? /*prepare the query*/ /*you have to change the query to adapt it to your table*/ if (col == 0) kolon = "english"; if (col == 1) kolon = "turkish"; String s = "update soz set " + kolon + " = '" + (String) value + "' where " + kolon + " = '" + ((String[]) cache.elementAt(row))[col] + "'"; System.out.println(s); /*excecute the query*/ try { statement.execute(s); } catch (Exception e) { System.out.println("Could not updated"); } ((String[]) cache.elementAt(row))[col] = (String) value; fireTableCellUpdated(row, col); // also update the table }
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
public void dispose() { try { stmt.close(); con.close(); } catch (SQLException e) { } }
private void jButton4ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: String wash = chrg.getText(); cname = custname.getText(); addr1 = addr.getText(); total.setText(String.valueOf(tamount)); String a = lcharge.getText(); String b = total.getText(); String j = la.getText(); String c = con.getText(); int d = Integer.parseInt(b); int e = Integer.parseInt(a); int g = Integer.parseInt(wash); int h = Integer.parseInt(c); int i = Integer.parseInt(j); int f = d + e + g + h + i; toamnt.setText(String.valueOf(f)); String sql = "insert into bill(Bill_No,Bill_Date,Cust_Name,Cust_Addr,P_Details,Amount) values('" + no1 + "','" + bill1 + "','" + cname + "','" + addr1 + "','" + pd + "','" + toamnt + "')"; try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", ""); Statement stmt = con.createStatement(); stmt.executeUpdate(sql); } catch (Exception e2) { JOptionPane.showMessageDialog(this, e2.getMessage()); } } // GEN-LAST:event_jButton4ActionPerformed
private void logOut(int personId) { Connection con = getConnect(); try { // MessageBox.infoBox("You have successfully logged out", "Logout"); // UPDATE LogInOut SET TimeOut = NOW() WHERE PersonId = 1 AND TimeOut IS NULL String SQLLogin = "******" + personId + " AND TimeOut IS NULL"; Statement stmtLogin = con.createStatement(); stmtLogin.executeUpdate(SQLLogin); Update_table(); } catch (SQLException err) { System.out.println(err); MessageBox.infoBox(err.toString(), "Error"); } closeConnect(); }
/** * 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
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 }
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; }
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) ."); } }
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); } }
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()); } } }
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; }
public void closeDB() { try { if (statement != null) { statement.close(); } if (db != null) { db.close(); } } catch (Exception e) { System.out.println("Database could not closed"); e.printStackTrace(); } } // closeDB sonu
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()"); } }
public void actionPerformed(ActionEvent e) { String name6 = JOptionPane.showInputDialog("Enter old Password:"******"Enter New Password:"******"jdbc:oracle:thin:@localhost:1521:xe", "system", "9696030257"); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select * from database where password='******'"); rs.next(); String k8 = rs.getString("password"); if (k8.equals(name6)) { st.executeUpdate( "update database set password='******' where password='******'"); JOptionPane.showMessageDialog(null, "Your Password has been Reset"); new Jf(); } } catch (Exception ex) { System.out.print(ex); JOptionPane.showMessageDialog(null, "Please Enter valid DATA ."); } }
private void jButton1ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String part = partno.getText(); String itemname = name.getText(); String qty1 = qty.getText(); String rate1 = rate.getText(); String no1 = no.getText(); String cname = custname.getText(); String bill1 = bill.getText(); String addr1 = addr.getText(); String ta = tax.getText(); String str1 = amount.getText(); DefaultTableModel model = (DefaultTableModel) Table.getModel(); model.addRow( new Object[] { (String.valueOf(++i)), partno.getText(), name.getText(), tax.getText(), qty.getText(), rate.getText(), amount.getText() }); pd = pd + "," + "(" + part + "," + itemname + "," + qty1 + ")"; tamount = tamount + Integer.parseInt(str1); try { Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", ""); Statement stmt2 = con.createStatement(); stmt2.executeUpdate( "UPDATE MOTORS SET QUANTITY=QUANTITY-'" + qty1 + "' WHERE ITEM_NAME='" + part + "'"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString()); } } // GEN-LAST:event_jButton1ActionPerformed