+ 1

How to search data from the database (jpa)

hi guys, does someone knows how to search data from the database(MySQL) using jpa ? I don't know how to do it, can somebody help?

23rd May 2018, 6:40 AM
Junny D. Silva
Junny D. Silva - avatar
8 odpowiedzi
+ 6
then write this code where you want to write it import java.sql.*; . . ResultSet rs=null; 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="your_sql_query"; rs=stmt.executeQuery(sql); rs.first(); //Assuming that you want to show your data in a label jLabel1.setText(rs.getString("name_of_the_column_from_where_you_want_to_recieve_the_data"); stmt.close(); conn.close(); } catch(Exception e) { System.out.println(e); }
27th Jun 2018, 11:37 AM
Siddharth Golecha
Siddharth Golecha - avatar
+ 6
first of all add SQL library to your project
27th Jun 2018, 11:01 AM
Siddharth Golecha
Siddharth Golecha - avatar
+ 6
go to project section in netbeans and then right click on the libraries folder. Click on add library option. select your desired library
27th Jun 2018, 11:03 AM
Siddharth Golecha
Siddharth Golecha - avatar
+ 5
if you are using netbeans I can help you
26th Jun 2018, 12:07 PM
Siddharth Golecha
Siddharth Golecha - avatar
+ 4
in which software you are developing your application?
26th Jun 2018, 12:05 PM
Siddharth Golecha
Siddharth Golecha - avatar
+ 4
actually I used that too for my high school project
27th Jun 2018, 12:44 PM
Siddharth Golecha
Siddharth Golecha - avatar
0
I'm using Neatbeans
26th Jun 2018, 12:53 PM
Junny D. Silva
Junny D. Silva - avatar
0
thank you so much for your help, it worked
27th Jun 2018, 12:39 PM
Junny D. Silva
Junny D. Silva - avatar