السلام عليكم ..
عندي مشكله مع ملفين جافا ،،
الاول ملف يتعامل مع الـ GUI و بعدين ينقل المعلومات الى ملف ثاني يتعامل مع الـ database
بالبداية،، انشأت هذا السطر بالملف الاول :
//create objects from another classes for using them in the ActionListener private addBooksConnection connection; //for creating an array of string to store the data private String[] data; //for setting availble option to true private boolean availble = true;
و بعدين كتبت ميثود معين للتعامل مع المعلومات:
//for checking the information from the text field
public boolean isCorrect() {
for(int i = 0; i < 8; i++) {
if(!informationTextField.getText().equals("")) {
data = new String[8];
data = informationTextField.getText();
}
else return false;
}
return true;
}و بعدين كتبت بنفس الملف الاول:
insertInformationButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if(isCorrect()) {
connection = new addBooksConnection();
connection.toConnection("INSERT INTO Books (Subject,Title,Author,"+
"Publisher,Copyright,Edition,Pages,ISBN,Availble) VALUES ('"+
data[0] + "','" + data[1] + "','" + data[2] + "','"+
data[3] + "', " + data[4] + ", " + data[5] + ", " +
data[6] + ", '" + data[7] + "', " + availble+ ")");
//for setting the JTextField[] text to null
for(int i = 0; i < informationTextField.length; i++) {
informationTextField.setText(null);
}
}
else {
JOptionPane.showMessageDialog(null,"Please, complete the information","Missing Information",JOptionPane.WARNING_MESSAGE);
}
}
});و كتبت بالملف الثاني هذا الكود:
//import the packages for using the classes in them into the program
import java.sql.*;
public class addBooksConnection {
/***************************************************************************
*** declaration of the private variables used in the program ***
***************************************************************************/
//for setting the connection and statement
private Connection connection = null;
private Statement statement = null;
public void toConnection(String query) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ea) {
System.out.println(ea.toString());
}
catch(Exception e) {
System.out.println(e.toString());
}
/***************************************************************
* for making the connection,creating the statement and update *
* the table in the database. After that,closing the statmenet *
* and connection. There is catch block SQLException for error *
***************************************************************/
try {
connection = DriverManager.getConnection("jdbc:odbc:JLibrary");
statement = connection.createStatement();
statement.executeUpdate(query);
statement.close();
connection.close();
}
catch(SQLException SQLe) {
System.out.println(SQLe.toString());
}
}
}المشكله الوحيده هي ان جميع الخانات بقاعدة البيانات تاخذ null ماعدا اخر عمودين،، فتطلع المعلومات مثل ما ادخلت من قبل المستخدم و البقيه تكون null !!
احد يعرف وين المشكله !!!
انا مستغرب ان بعض المعلومات تدخل لقاعدة البيانات و البعض الاخر لا يدخل !!