java程序运行后,在表单中提供详细信息后,表单会出现,它应该将数据放入我的数据库中,但每次提供数据后,它只会在所有行中显示“deleted”。在编译和运行java文件时,我的insert查询或数据库连接是否有任何问题?它没有显示任何类型的错误或警告。
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
@SuppressWarnings("deprecation")
public class Anpr extends JFrame implements ActionListener{
ImageIcon icon;
ImageIcon img3;
JLabel imglab3,label3,label4,label5,label6,label7,label8,label9,label10;
Dimension dimension;
JTextField pid,name,cno,age,bgrp,addr,anydis;
JComboBox<String> gen;
Anpr(){
dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x=(int)((dimension.getWidth() - 650)/2);
int y=(int)((dimension.getHeight() - 650)/2);
setLocation(x, y);
setSize(600,600);
setLayout(null);
setUndecorated(true);
// setDefaultCloseOperation(EXIT_ON_CLOSE);
icon = new ImageIcon("image/medical-record.png");
setIconImage(icon.getImage());
setTitle("Add New Patient Record");
setResizable(false);
label3 = new JLabel("Patient ID");
label3.setBounds(150,50,80,30);
label4 = new JLabel("Name");
label4.setBounds(150,90,80,30);
label5 = new JLabel("Contact No");
label5.setBounds(150,130,80,30);
label6 = new JLabel("Age");
label6.setBounds(150,170,80,30);
label7 = new JLabel("Gender");
label7.setBounds(150,210,80,30);
label8 = new JLabel("Blood Group");
label8.setBounds(150,250,80,30);
label9 = new JLabel("Address");
label9.setBounds(150,290,80,30);
label10 = new JLabel("Any Major Disease Suffered Earlier");
label10.setBounds(150,330,200,30);
add(label3);
add(label4);
add(label5);
add(label6);
add(label7);
add(label8);
add(label9);
add(label10);
JButton btnsa=new JButton("Save");
JButton btnco=new JButton("Close");
btnsa.setBounds(150,450,80,30);
btnco.setBounds(350,450,80,30);
add(btnsa);
add(btnco);
btnsa.addActionListener(this);
btnco.addActionListener(this);
pid = new JTextField();
pid.setBounds(270,50,180,30);
name = new JTextField();
name.setBounds(270,90,180,30);
cno = new JTextField();
cno.setBounds(270,130,180,30);
age = new JTextField();
age.setBounds(270,170,180,30);
gen = new JComboBox<String>(new String[] {"Male","Female","Other"});
gen.setBounds(270,210,180,30);
bgrp = new JTextField();
bgrp.setBounds(270,250,180,30);
addr = new JTextField();
addr.setBounds(270,290,180,30);
anydis = new JTextField();
anydis.setBounds(150,370,300,30);
add(pid);
add(name);
add(cno);
add(age);
add(gen);
add(bgrp);
add(addr);
add(anydis);
// Background image
img3 = new ImageIcon("image/m_back2.jpg");
imglab3 = new JLabel(img3);
imglab3.setSize(600,600);
add(imglab3);
}
public void actionPerformed(ActionEvent ael){
String str1 =ael.getActionCommand();
String PatientID =pid.getText();
String Pname =name.getText();
String ContactNumber =cno.getText();
String ages=age.getText();
String gender=(String)gen.getSelectedItem();
String bloodGroup=bgrp.getText();
String address=addr.getText();
String anyMajorDisease=anydis.getText();
if(str1.equals("Save")){
try {
String url="jdbc:ucanaccess://Hospital.accdb";
Connection connection=DriverManager.getConnection(url);
Statement st=connection.createStatement();
st.executeUpdate("insert into Patient(PatientID,Pname,ContactNumber,ages,gender,bloodGroup,address,anyMajorDisease) values('"+PatientID+"','"+Pname+"','"+ContactNumber+"','"+ages+"','"+gender+"','"+bloodGroup+"','"+address+"','"+anyMajorDisease+"')");
JOptionPane.showMessageDialog(null,"Added New Patient Record Successfull");
}catch(Exception ex){
ex.printStackTrace();
}
}
else if(str1.equals("Close")){
System.exit(0);
}
}
public static void main(String[] args){
Anpr apr=new Anpr();
apr.setVisible(true);
}
}
1条答案
按热度按时间dpiehjr41#
deleted是一条microsoft access应用程序错误消息,可能有许多潜在原因。当所有数据显示为“已删除”时,主键值通常会出现问题,超出ms access支持的范围。
检查插入表中的所有值,确保它们不超过指定数据类型的最大大小(例如,varchar中的字符太多,或者数值超出范围)。还要确保不要在需要数值的地方使用字符串值(使用的jdbc驱动程序可能会将字符串转换为未指定的数值)