我想從數據庫中刪除客戶的有關新聞紙而不是客戶的全部細節? 一位顧客在他們的記錄中有多張紙,但我想從多張紙中刪除任何紙張。 我是輸入客戶ID和選擇界河紙我想刪除 感謝先進的幫助...JDBC ODBC刪除查詢錯誤問題?
enter code here:
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.*;
public abstract class delete_paper extends JFrame implements ActionListener
{
JTextField textFieldId;
JLabel l1;
JLabel l3;
JLabel l5;
JLabel l6;
JComboBox combo;
String course[] = {"Navakal","SandhyaKal","Pudhari",
"MidDay","Inqlab","BusinessLine","MumbaiSamachar",
"GujrajSamachar","KarnatakMalla","Vartahar","PunyaNagari"};
JButton b2;
Container c = getContentPane();
delete_paper()
{
super("Shree DattaDigambar Samarth");
setBounds(140,250,777,555);
c.setLayout(null);
textFieldId = new JTextField();
l1 = new JLabel("New Customer Entry");
l3 = new JLabel("Customer Name");
l5 = new JLabel("Paper");
combo = new JComboBox(course);
l1.setBounds(10,10,340,20);
l3.setBounds(110,20,140,70);
l5.setBounds(400,50,140,20);
textFieldId.setBounds(10,70,70,20);
combo.setBounds(400,70,130,20);
b2 = new JButton("Ok");
b2.setBounds(10,160,50,20);
c.add(combo);
c.add(b2);
c.add(l1);
c.add(l3);
c.add(l5);
c.add(textFieldId);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
b2.addActionListener(this);
}
public static void main(String[] args)
{
delete_paper ap=new delete_paper() {};
}
public void actionPerformed(ActionEvent e)
{
System.out.println("You clicked the button");
if(e.getSource()==b2)
{
try
{
Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:devendra");
try
{
java.sql.Statement st = con.createStatement();
PreparedStatement ps = con.prepareStatement("delete
from Customer where Customer_Id = ? and Paper_Name in (?) ");
ps.setString(1,textFieldId.getText());
ps.setString(4,combo.getSelectedItem().toString());
ps.executeUpdate();
JOptionPane.showMessageDialog(null,
"You successfully Enter the Entry");
}
catch (SQLException s)
{
System.out.println("SQL code does not execute.");
JOptionPane.showMessageDialog(null,"Please Enter
the Detail Correctly");
}
}
catch (ClassNotFoundException | SQLException ee)
{
System.out.println("Error:connection not created");
JOptionPane.showMessageDialog(null,"Please
Enter the Detail Correctly");
}
}
}
}
添加堆棧跟蹤信息。 –
對類使用java命名約定。不要使用null佈局和setBounds。定義正確的Layoutmanager。不要在對話框和JOptionPanes中使用空父對象。用一些合理的名稱命名變量不是label1,label2。應只捕獲一次SQLException。不要每次點擊都準備好聲明。準備一次並重復使用。在您的文字中使用大寫字母以幫助讀者分割您的文字。張貼SSCCE和儘可能多的細節(合理)。比尋求幫助。 – StanislavL
@StanislavL哇! 8(如果我計算正確)指出'問題的重要提示'..作爲評論..幹得好。 :) –