Path: csiph.com!news.fcku.it!bofh.it!diesel.cu.mi.it!.POSTED!not-for-mail From: enzodb@diesel Newsgroups: it.comp.java Subject: non so dove sia l'errore !!! Date: Mon, 11 Jul 2016 13:33:30 +0200 Organization: C.U. srl News Server Lines: 184 Message-ID: NNTP-Posting-Host: 2-236-61-38.ip232.fastwebnet.it Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: virtdiesel.mng.cu.mi.it 1468236768 1829 2.236.61.38 (11 Jul 2016 11:32:48 GMT) X-Complaints-To: abuse@diesel.cu.mi.it NNTP-Posting-Date: Mon, 11 Jul 2016 11:32:48 +0000 (UTC) User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 X-Mozilla-News-Host: news://diesel.cu.mi.it:119 Xref: csiph.com it.comp.java:8943 Salve,importato questo codice su eclipse, vengono segnalate errate le righe 72,73,74,75,109,154 e 155. Non riesco a dipanare questa matassa ! Qualcuno "caritatevole" riesce a darmi una mano ?!? Grazie anticipate ! _______________________________________________________________________ 1> //import statement 2> import java.awt.EventQueue; 3> import java.awt.event.ActionEvent; 4> import java.awt.event.ActionListener; 5> import java.sql.Connection; 6> import java.sql.DriverManager; 7> import java.sql.SQLException; 8> import java.sql.Wrapper; 9> 10> import javax.swing.JButton; 11> import javax.swing.JFrame; 11> import javax.swing.JLabel; 12> import javax.swing.JOptionPane; 13> import javax.swing.JPanel; 14> import javax.swing.JTextField; 15> import javax.swing.border.EmptyBorder; 16> 17> public class NewUser extends JFrame //create class NewUser 18> { 19> private JPanel contentPane; //declare variable 20> private JTextField txtUser; 21> private JButton btnSignup; 22> private JTextField txtPassword; 23> protected java.lang.String Spassword; 24> 25> // database URL 26> static final String DB_URL = "jdbc:mysql://localhost/demo"; 27> 28> // Database credentials 29> static final String USER = "root"; 30> static final String PASS = "root"; 31> protected static final String String = null; 32> 33> /** 34> * Launch the application. 35> */ 36> public static void main(String[] args) // main method 37> { 38> EventQueue.invokeLater(new Runnable() 39> { 40> public void run() //define run method 41> { 42> try //try block 43> { 44> //create NewUser frame object 45> NewUser frame = new NewUser(); 46> //set NewUser frame visible 47> frame.setVisible(true); 48> } 49> catch (Exception e) //catch block 50> { 51> e.printStackTrace(); 52> } 53> } 54> }); 55> } 56> 57> /** 58> * Create the frame. 59> */ 60> public NewUser() //create constructor 61> { 62> //set title 63> setTitle("New User Login"); 64> //set close operation 65> setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 66> //set bounds of frame 67> setBounds(100, 100, 450, 300); 68> //create object of JPanel 69> contentPane = new JPanel(); 70> //set contentPane border 71> contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 72> set ContentPane with new object 73> setContentPane(contentPane); 74> set contentPane layout is null 75> contentPane.setLayout(null); 76> 77> // create text field for user 78> txtUser = new JTextField(); 79> //set bounds for text fields 80> txtUser.setBounds(188, 51, 99, 20); 81> //in contentPane add text field 82> contentPane.add(txtUser); 83> //set column for text field 84> txtUser.setColumns(10); 85> 86> //lable the text field 87> JLabel lblUserName = new JLabel("User Name"); 88> //set bounds for label 89> lblUserName.setBounds(70, 54, 86, 14); 90> //add into contentPane 91> contentPane.add(lblUserName); 92> 93> //lable the text field 94> JLabel lblPassword = new JLabel("Password"); 95> //set bounds for label 96> lblPassword.setBounds(70, 109, 86, 14); 97> //add into contentPane 98> contentPane.add(lblPassword); 99> 100> //create button signup 101> btnSignup = new JButton("SignUp"); 102> //add event handler on SignUp button 103> btnSignup.addActionListener(new ActionListener() 104> { 105> public void actionPerformed(ActionEvent e) 106> { 107> } 108> //Create wrapper object and define it null 109> Wrapper conn = null; 110> try //try block 111> { 112> //declare variables 113> String username = ""; 114> String password = ""; 115> 116> //get values using getText() method 117> username = txtUser.getText().trim(); 118> password = txtPassword.getText().trim(); 119> 120> // check condition it field equals to blank throw error message 121> if (username.equals("")|| password.equals("")) 122> { 123> JOptionPane.showMessageDialog(null," name or password or Role is wrong","Error",JOptionPane.ERROR_MESSAGE); 124> } 125> else //else insert query is run properly 126> { 127> String IQuery = "INSERT INTO `demo`.`loginaccount`(`username`,`password`,`ts`) VALUES('"+username+"', '"+password+"',current_timestamp)"; 128> System.out.println(IQuery);//print on console 129> System.out.println("Connecting to a selected database..."); 130> 131> //STEP 3: Open a connection 132> conn = DriverManager.getConnection(DB_URL, USER, PASS); 133> System.out.println("Connected database successfully..."); 134> 135> ((Connection)conn).createStatement().execute(IQuery);//select the rows 136> // define SMessage variable 137> String SMessage = "Record added for "+username; 138> 139> // create dialog ox which is print message 140> JOptionPane.showMessageDialog(null,SMessage,"Message",JOptionPane.PLAIN_MESSAGE); 141> //close connection 142> ((java.sql.Connection)conn).close(); 143> } 144> } 145> catch (SQLException se) 146> { 147> //handle errors for JDBC 148> se.printStackTrace(); 149> } 150> catch (Exception a) //catch block 151> { 152> a.printStackTrace(); 153> } 154> } 155> }); 156> //set bound for SignUp button 157> btnSignup.setBounds(131, 165, 89, 23); 158> //add button into contentPane 159> contentPane.add(btnSignup); 160> 161> //create text field for password 162> txtPassword = new JTextField(); 163> //set bound for password field 164> txtPassword.setBounds(188, 106, 99, 20); 165> //add text field on contentPane 166> contentPane.add(txtPassword); 167> set column for password text field 168> txtPassword.setColumns(10); 169> } 170> }