السلام عليكم ورحمة الله وبركاته
اخواني انا عملت في مشروعي كلاس منفرد للإرتباط بقاعدة البيانات mysql وهذا هو:
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class StoreManegment {
//public static void main(String[] args) {
static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
static final String DATABASE_URL="jdbc:mysql://localhost/store";
static final String USERNAME = "root";
static final String PASSWORD = "root";
Connection conn = null;
public void connect() throws SQLException{
try {
Class.forName(JDBC_DRIVER);
Connection con=(Connection) DriverManager.getConnection(DATABASE_URL,USERNAME,PASSWORD);
//prepared statement
System.out.println("connected successfully");
} catch (ClassNotFoundException ex) {
Logger.getLogger(StoreManegment.class.getName()).log(Level.SEVERE, null, ex);
}//end try/catch
}//end connect method
}//endوالحمدلله عمل بنجاح
ولكن الآن اريد كود لربط الjframe في نفس المشروع بهذا الكود حتى استطيع استخراج البيانات من قاعدة البيانات
علما بأني قمت باستخدام هذا الكود ولكن عندما اعمل run للبرنامج الjfram الخاص باستخراج اليوزر والباسوورد من الديتابيس لا يعمل بمعنى انه ينقلني الى الjframالاخرى بادخال اي يوزر وباسوورد
private void initComponents()
{
try
{
conn = DriverManager.getConnection(StoreManegment.DATABASE_URL , StoreManegment.USERNAME , StoreManegment.PASSWORD);
statement = conn.createStatement();
// Result set get the result of the SQL query
resultSet = statement.executeQuery("select * from adminstrator");
while (resultSet.next())
{
int a = resultSet.getInt(1);
float b = resultSet.getFloat(4);
String c = resultSet.getString(2);
String d = resultSet.getString(3);
personne ym = new personne(a, b, c, d);
k.add(ym);
}
} catch (Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null, "error");
}
}
final String wrong= "Incorrect Password or username";
if (isLoggedIn(user.getText(), pword.getText())){
adminMain a=new adminMain();
a.setSize(816,628);
a.setVisible(true);
dispose();
}else
{
JOptionPane.showMessageDialog(rootPane, wrong);
}}
boolean isLoggedIn(final String userName, final String password)
{
String sql = "SELECT * FROM adminstrator where admin_user = ? and admin_pass = ?";
// set parameters and execute query
// ResultSet rs = ....
return true; // if found in Database, otherwise return false;
}فما الحل؟؟