Email ID | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Email ID

I wan to insert the user Id as email id to my database through the java netbeans text field can anyone help me?

14th Mar 2018, 5:07 PM
Mohamed Shafnas
Mohamed Shafnas - avatar
2 Answers
+ 6
first of all add SQL library to your project. go to project section in netbeans and then right click on the libraries folder. Click on add library option. select your desired library. then write this code where you want to write it import java.sql.*; . . String userid=jTextField1.getText(); try{ Class.forName("java.sql.DriverManager"); Connection conn=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/project_name","mysql_password","mysql_password"); Statement stmt=(Statement)conn.createStatement(); String sql="insert into database_name(emailid) value ("+userid+");"; stmt.executeUpdate(sql); stmt.close(); conn.close(); } catch(Exception e) { System.out.println(e); }
1st Jul 2018, 10:39 AM
Siddharth Golecha
Siddharth Golecha - avatar
0
sure, you need JDBC and driver installed then you can use preparef statement to execute your sql query.
14th Mar 2018, 8:31 PM
Pavan Kumar T S
Pavan Kumar T S - avatar