좋은 하루. 아무도 내 데이터베이스의 문제로 겪고있는 일을 실제로 도울 수 있습니까? pepraredStatement를 사용하여 데이터베이스에 삽입하려고합니다. 그러나 내가 데이터베이스 부분 (connection과 pepraredStatement)을 추가 할 때마다 'UPLOAD'버튼이 반응하지 않게됩니다. 하지만 데이터베이스와 관련된 모든 것을 제거하면 모든 버튼이 작동합니다. 여기에서 코드 http://pastebin.com/euKdWhr2을 찾을 수 있습니다.jbutton 문제가있는 mysql 데이터베이스에 저장
정말 도움이나 제안을 부탁드립니다. 아마도 나는 데이터베이스 부분에 뭔가 빠져 있습니다. 내가 정답 공공 무효의 actionPerformed (ActionEvent의의 EV) { 문자열 파일 = fileField.getText을 발견하지 않았기 때문에
그리고(), 그것은 중복 된 질문이 아니다하시기 바랍니다; SetGetQuestionFileName 패턴 = 새 SetGetQuestionFileName (파일); ConnectToDatabase database = new ConnectToDatabase(); {
///////// check whether textfile is empty or not
if(ev.getActionCommand().equals("UPLOAD"))
{
if(fileField.getText().isEmpty())
{
JOptionPane.showMessageDialog(null,"File field can not be empty!!! Please try again.","ALERT", JOptionPane.ERROR_MESSAGE);
}
else
{
File fi = new File(fileField.getText());
//////////////// perform upload
try
{
String sql = "INSERT INTO testsystem.questionnaire (category_questions, questions, correct_answer)" + "VALUES (?, ?, ?)";
PreparedStatement st = null;
Connection dbconnection = database.getConnection();
st = dbconnection.prepareStatement(sql);
if(fi.getAbsoluteFile().exists())
{
List<String> lines = Files.readAllLines(Paths.get(fileField.getText()), Charset.defaultCharset());
for (int i = 0; i < lines.size(); i+=10)
{
String category = lines.get(i);
System.out.println(category);
String question = lines.get(i+1);
System.out.println(question);
String answers =
lines.get(i+2)+System.lineSeparator()
+lines.get(i+3)+System.lineSeparator()
+lines.get(i+4)+System.lineSeparator()
+lines.get(i+5);
System.out.println(answers);
String correct = lines.get(i+7);
System.out.println("correct answer is: "+correct);
System.out.println("----------------");
st.setString(1, category);
st.setString(2, answers);
st.setString(3, correct);
st.executeUpdate();
}
JOptionPane.showMessageDialog(null,"File has been successfully uploaded in the database.","NOTIFCATION",JOptionPane.INFORMATION_MESSAGE);
}
else
JOptionPane.showMessageDialog(null,"File could not be found. Please try again","ALERT",JOptionPane.ERROR_MESSAGE);
}
catch(SQLException ex)
{
}
catch(Exception ex)
{
}
당신은 당신이 안내 할 수 괜찮다면, 그래서 난 정말, 스레드가 있었다하지 않았다 부분 중 하나 내 코드 부분에서 나를 – mkwilfreid
지금 내 PC에서 아니에요, 당신은 빠른 해킹을 고려하고 당신이 얻을 수있는 볼 수 있습니다 그리고 내가 시도하고 나중에 작은 예제를 게시합니다 – MadProgrammer