import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class addBooks extends JDialog {
private Connection connection = null;
private Statement statement = null;
private ResultSet resultset = null;
private JPanel northPanel = new JPanel();
private JLabel northLabel = new JLabel("Add the information for the book...");
private JPanel centerPanel = new JPanel();
private JLabel bookIDLabel;
private JTextField bookIDTextField = new JTextField();
private String bookID = null;
private JLabel titleLabel;
private JTextField titleTextField = new JTextField();
private String title = null;
private JLabel autherLabel;
private JTextField autherTextField = new JTextField();
private String authers = null;
private JLabel publisherLabel;
private JTextField publisherTextField = new JTextField();
private String publisher = null;
private JLabel editionNumberLabel;
private JTextField editionNumberTextField = new JTextField();
private String editionNumber = null;
private JLabel copyrightLabel;
private JTextField copyrightTextField = new JTextField();
private String copyrightYear = null;
private JLabel pagesLabel;
private JTextField pagesTextField = new JTextField();
private String pages = null;
private JLabel ISBNLabel;
private JTextField ISBNTextField = new JTextField();
private String ISBN = null;
private JPanel southPanel = new JPanel();
private JButton insertInformationButton = new JButton("Insert the Information");
private JLibrary l;
public addBooks(JLibrary l) {
this.l = l;
}
public void addBooks(Frame frame, String _title, boolean model) {
setTitle(_title);
Container cp = getContentPane();
northPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
northLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
northPanel.add(northLabel);
cp.add("North", northPanel);
centerPanel.setLayout(new GridLayout(8,8,1,1));
centerPanel.add(bookIDLabel = new JLabel(" Write the Book ID:"));
centerPanel.add(bookIDTextField);
centerPanel.add(titleLabel = new JLabel(" Write the title:"));
centerPanel.add(titleTextField);
centerPanel.add(autherLabel = new JLabel(" Write the name of the auther:"));
centerPanel.add(autherTextField);
centerPanel.add(publisherLabel = new JLabel(" Write the name of the publisher:"));
centerPanel.add(publisherTextField);
centerPanel.add(editionNumberLabel = new JLabel(" Write the Edition Number:"));
centerPanel.add(editionNumberTextField);
centerPanel.add(copyrightLabel = new JLabel(" Write the copyright for the book:"));
centerPanel.add(copyrightTextField);
centerPanel.add(pagesLabel = new JLabel(" Write the number of pages:"));
centerPanel.add(pagesTextField);
centerPanel.add(ISBNLabel = new JLabel(" Write ISBN for the book:"));
centerPanel.add(ISBNTextField);
cp.add("Center", centerPanel);
southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
southPanel.add(insertInformationButton);
cp.add("South", southPanel);
insertInformationButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
bookID = bookIDTextField.getText();
title = titleTextField.getText();
authers = autherTextField.getText();
publisher = publisherTextField.getText();
editionNumber = editionNumberTextField.getText();
copyrightYear = copyrightTextField.getText();
pages = pagesTextField.getText();
ISBN = ISBNTextField.getText();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e) {
System.out.println(e.toString());
}
try {
connection = DriverManager.getConnection("jdbc:odbc:Library");
statement = connection.createStatement();
statement.executeUpdate("INSERT INTO Books (bookID,Title,authers,"+
"publisher,editionNumber,copyrightYear,Pages,ISBN) VALUES ("+bookID+","+title+","+authers+","+
publisher+","+editionNumber+","+copyrightYear+","+pages+","+ISBN+")");
statement.close();
connection.close();
}
catch(SQLException SQLe) {
System.out.println(SQLe.toString());
}
}
});
setResizable(false);
setVisible(true);
pack();
}
}كتبت هذا الكود لادخال بيانات كتاب الى قاعده البيانات لكن المشكله اللي تطلع لي هي :
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
وين المشكله بالضبط ؟؟