애플릿 페이지를 사용하여 mysql 데이터베이스에 데이터를 추가하려고합니다. 내 생각은 텍스트 필드를 채우고 나서 저장 버튼을 누르면 모든 텍스트가 mySQL 데이터베이스에 추가됩니다. 하지만 오류가 있습니다.애플릿 textfield에서 mysql 데이터베이스에 데이터를 삽입하십시오 - 오류
Access Denied: java.security.AccessControlException:access denied
(java.io.FilePermision "\C:\Program Files(x86)\MySQL\mysql-connector-java-5.1.30\mysql-connector-java-5.1.30-bin.jar" "read")
미리 감사드립니다. 여기에 내 코드입니다 :. ((
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.SwingUtilities;
import javax.swing.JApplet;
import java.sql.*;
import java.net.*;
public class AddBook extends JApplet
{
JButton btnSave, btnCancel;
JLabel lblIsbn, lblTitle, lblCategory, lblAuthor, lblYPublish, lblPublisher, lblCopies, lblYear, lblMsg1;
JTextField txtTitle, txtCategory;
JTextField txtIsbn, txtAuthor, txtPublisher, txtCopies, txtYear;
String ttitle, tauthor, tpublisher, tcategory, tisbn, tyear, tqty;
public void init()
{
Font fonttxt = new Font("Calibri", Font.PLAIN, 16);
Font fontlbl = new Font("Calibri",Font.BOLD, 14);
Font fontbtn = new Font("Calibri",Font.BOLD, 16);
Font fontTitle = new Font("Arial ",Font.BOLD,30);
setLayout(null);
setSize(410, 400);
setBackground(Color.gray);
btnSave = new JButton("Save");
btnSave.setFont(fontbtn);
btnCancel = new JButton("Cancel");
btnCancel.setFont(fontbtn);
lblMsg1 = new JLabel ("ADD BOOK");
lblMsg1.setFont(fontbtn);
lblIsbn = new JLabel("ISBN :");
lblIsbn.setFont(fontlbl);
lblTitle = new JLabel ("Title :");
lblTitle.setFont(fontlbl);
lblCategory = new JLabel ("Category :");
lblCategory.setFont(fontlbl);
lblAuthor = new JLabel ("Author :");
lblAuthor.setFont(fontlbl);
lblYear = new JLabel ("Year Published :");
lblYear.setFont(fontlbl);
lblPublisher = new JLabel ("Publisher :");
lblPublisher.setFont(fontlbl);
lblCopies = new JLabel ("Number of Copies :");
lblCopies.setFont(fontlbl);
JTextField txtIsbn = new JTextField ("",100);
txtIsbn.setFont(fonttxt);
JTextField txtTitle = new JTextField ("",100);
txtTitle.setFont(fonttxt);
JTextField txtCategory = new JTextField ("",100);
txtCategory.setFont(fonttxt);
JTextField txtAuthor = new JTextField ("",100);
txtAuthor.setFont(fonttxt);
JTextField txtPublisher = new JTextField ("",100);
txtPublisher.setFont(fonttxt);
JTextField txtCopies = new JTextField ("",100);
txtCopies.setFont(fonttxt);
JTextField txtYear = new JTextField ("",100);
txtYear.setFont(fonttxt);
lblMsg1.setBounds(10,10,200,40);
lblIsbn.setBounds(10,50,250,30);
txtIsbn.setBounds(130,50,250,30);
lblTitle.setBounds(10,90,250,30);
txtTitle.setBounds(130,90,250,30);
lblCategory.setBounds(10,130,250,30);
txtCategory.setBounds(130,130,250,30);
lblAuthor.setBounds(10,165,250,30);
txtAuthor.setBounds(130,165,250,30);
lblPublisher.setBounds(10,200,250,30);
txtPublisher.setBounds(130,200,250,30);
lblCopies.setBounds(10,240,250,30);
txtCopies.setBounds(130,240,250,30);
lblYear.setBounds(10,280,250,30);
txtYear.setBounds(130,280,250,30);
btnSave.setBounds(40,320,150,35);
btnCancel.setBounds(200,320,150,35);
add(lblMsg1);
add(txtIsbn);
add(txtTitle);
add(txtCategory);
add(txtAuthor);
add(txtPublisher);
add(txtCopies);
add(txtYear);
add(lblIsbn);
add(lblTitle);
add(lblCategory);
add(lblAuthor);
add(lblPublisher);
add(lblCopies);
add(lblYear);
add(btnSave);
add(btnCancel);
tisbn = txtIsbn.getText();
tyear = txtYear.getText();
tqty = txtCopies.getText();
ttitle = txtTitle.getText();
tauthor = txtAuthor.getText();
tcategory = txtCategory.getText();
tpublisher = txtPublisher.getText();
btnSave.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
//Connection con = null;
//Statement st = null; 1
PreparedStatement pstmt;
Connection con;
if(ae.getSource() == btnSave)
{
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/library_system", "root", "password");
con.setAutoCommit(false);
pstmt = con.prepareStatement ("INSERT INTO book_records VALUES (?, ?, ?, ?, ?, ?, ?)");
pstmt.setString(1, tisbn);
pstmt.setString(2, ttitle);
pstmt.setString(3, tauthor);
pstmt.setString (4, tyear);
pstmt.setString(5, tpublisher);
pstmt.setString(6, tcategory);
pstmt.setString(7, tqty);
pstmt.executeUpdate();
con.commit();
pstmt.close();
}
catch(Exception err)
{
JOptionPane.showMessageDialog(null, "Access Denied: "+err);
}
}
}
}
});
}
}
전체 스택 추적 오류를 표시해야합니다! –
전체 오류로 인해 "액세스가 거부되었습니다. java.security.AccessControlException : 액세스가 거부되었습니다 ("java.io.FilePermision "\ C : \ Program Files (x86) \ MySQL \ mysql-connector-java-5.1.30 \ mysql-connector-java-5.1.30-bin.jar ""read ") – KidCoder