Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.java > #8943

non so dove sia l'errore !!!

From enzodb@diesel <enzodibattista@gesis.it>
Newsgroups it.comp.java
Subject non so dove sia l'errore !!!
Date 2016-07-11 13:33 +0200
Organization C.U. srl News Server
Message-ID <nm0050$1p5$1@virtdiesel.mng.cu.mi.it> (permalink)

Show all headers | View raw


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> }

Back to it.comp.java | Previous | NextNext in thread | Find similar


Thread

non so dove sia l'errore !!! enzodb@diesel <enzodibattista@gesis.it> - 2016-07-11 13:33 +0200
  Re: non so dove sia l'errore !!! "Dr.UgoGagliardelli" <do.not.spam@me.please> - 2016-07-11 14:44 +0200

csiph-web