| | |
Registering system, Unwanted behavior
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2009
Posts: 36
Reputation:
Solved Threads: 0
Hello, I've made registering system to my little test program, It works well until you try to create two accounts with same name, It shouldn't allow it but it still does it. I have tried to solve this problem all day now by trying diffrent methods but sadly nothing helped. So if any of you geniuses could help me out.
I think that maybe that INNER JOIN affects it somehow, I tried with left and right but then it gives sql error. Im hopeless.
By the way if you need to test the program in it self add me in msn samppa.l@hotmail.com.
Java Syntax (Toggle Plain Text)
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * Regform.java * * Created on 21.8.2009, 14:29:46 */ /** * * @author Samuli */ import java.sql.*; import java.util.logging.Level; import java.util.logging.Logger; public class Regform extends javax.swing.JFrame { /** Creates new form Regform */ public Regform() { initComponents(); this.setLocation(800, 400); this.setTitle("Registeration"); this.setResizable(false); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") public static boolean Cancreate = true; // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jSeparator1 = new javax.swing.JSeparator(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); Password = new javax.swing.JPasswordField(); Name = new javax.swing.JTextField(); Key = new javax.swing.JTextField(); Proceed = new javax.swing.JButton(); Cancel = new javax.swing.JButton(); Status = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText("Registeration"); jLabel2.setText("Welcome to registeration if you don't know what to do, go away"); jLabel3.setText("Username:"); jLabel4.setText("Password:"); jLabel5.setText("Registeration Key:"); Proceed.setText("Proceed"); Proceed.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ProceedActionPerformed(evt); } }); Cancel.setText("Cancel"); Cancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { CancelActionPerformed(evt); } }); Status.setText("Status text"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(44, 44, 44) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Key, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Name)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(Password, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(Cancel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(Proceed, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))) .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING))) .addContainerGap(61, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 356, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(104, 104, 104) .addComponent(Status, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(16, 16, 16) .addComponent(Status) .addGap(2, 2, 2) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addGap(18, 18, 18) .addComponent(jLabel2) .addGap(27, 27, 27) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(Name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(Proceed)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(Cancel) .addComponent(Password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(Key, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold> @SuppressWarnings("empty-statement") private void ProceedActionPerformed(java.awt.event.ActionEvent evt) { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e) { return; } try { con = DriverManager.getConnection("jdbc:mysql://MY IP/breakpoint","root", "Secret"); Statement st = con.createStatement (); Statement stm = con.createStatement(); Statement st2 = con.createStatement(); st.executeQuery("SELECT Users.Username,Users.Password,Avaimet.Avainrekisteriin FROM Users INNER JOIN Avaimet "); ResultSet rss = st.getResultSet(); String Accname = Name.getText(); String Accpass = Password.getText(); String Regkey = Key.getText(); boolean Created = false; while ( rss.next() ) { String name = rss.getString("Username"); String key = rss.getString("Avainrekisteriin"); if (Accname.length() <= 3) Status.setText("Your account name has to be longer than 3 letters"); else if (Accpass.length() <= 3) Status.setText("Your account password has to be longer than 3 letters"); if ( Created == false && Accname.equalsIgnoreCase(name) && Regkey.equalsIgnoreCase(key) ) { String Deletekey = "DELETE FROM Avaimet WHERE Avainrekisteriin = '"+key+"'"; String StrSQL = "INSERT INTO Users (Username,Password,Banned,Level,Admin) " + "VALUES ('"+Accname+"','"+Accpass+"',"+0+",'3','0')"; stm.executeUpdate(StrSQL); st2.executeUpdate(Deletekey); Created = true; System.out.print("ACC CREATED"); Status.setText("Account created!"); Form1.Status.setText("Account created!"); this.dispose(); } else { Status.setText("Something failed!"); } } st.close(); rss.close(); } catch (SQLException e) { System.out.println("Connection Failed! Check output console"); e.printStackTrace(); return; } } private void CancelActionPerformed(java.awt.event.ActionEvent evt) { this.dispose(); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Regform().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton Cancel; private javax.swing.JTextField Key; private javax.swing.JTextField Name; private javax.swing.JPasswordField Password; private javax.swing.JButton Proceed; private javax.swing.JLabel Status; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JSeparator jSeparator1; // End of variables declaration }
I think that maybe that INNER JOIN affects it somehow, I tried with left and right but then it gives sql error. Im hopeless.
By the way if you need to test the program in it self add me in msn samppa.l@hotmail.com.
Last edited by Silvershaft; Aug 22nd, 2009 at 4:35 pm.
•
•
Join Date: Jun 2008
Posts: 46
Reputation:
Solved Threads: 1
hi, i could not test your program because it did not compile..but i think your problem could be in compairing objects rather than their values.
if ( Created == false && Accname.equalsIgnoreCase(name) && Regkey.equalsIgnoreCase(key) )
i think your problem could be in this line..here you are comparing if the two objects(in this case Accname and name) are the same object. You should try comparing the values. An '==' operator would do that.
Hope this helpss
if ( Created == false && Accname.equalsIgnoreCase(name) && Regkey.equalsIgnoreCase(key) )
i think your problem could be in this line..here you are comparing if the two objects(in this case Accname and name) are the same object. You should try comparing the values. An '==' operator would do that.
Hope this helpss
![]() |
Similar Threads
- system("CD"). Help please :( (C++)
- 2 windows xp OSs on my compter (Windows NT / 2000 / XP)
- C program please help (C)
- PC Cleaning Procedures & Detection Tools (Viruses, Spyware and other Nasties)
- looking for advice before i purchase registry cleaner. (Windows Software)
- SYSTEM.INI missing on WIN 98 SE (Windows 95 / 98 / Me)
- please help me with my windows xp (Viruses, Spyware and other Nasties)
- CSS Quicky (HTML and CSS)
Other Threads in the Java Forum
- Previous Thread: Need quick help
- Next Thread: JavaEE
Views: 277 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android api apple applet application arguments array arrays automation binary block bluetooth chat class classes client code compile component database developmenthelp draw eclipse encode error event exception file fractal freeze game gameprogramming givemetehcodez graphics gui helpwithhomework html ide image input integer iphone j2me j2seprojects java javac javaprojects jmf jni jpanel julia lego linux list loop loops mac map method methods mobile netbeans newbie notdisplaying number object online oracle print problem program programming project recursion scanner screen server set singleton size sms socket sort sql string swing system template test textfields threads time title transfer tree tutorial-sample update windows working





