+ 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?
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);
}
+ 6
first of all add SQL library to your project
+ 6
go to project section in netbeans and then right click on the libraries folder. Click on add library option. select your desired library
+ 5
if you are using netbeans I can help you
+ 4
in which software you are developing your application?
+ 4
actually I used that too for my high school project
0
I'm using Neatbeans
0
thank you so much for your help, it worked