gpt4 book ai didi

java - 无法在请求的时间内获得锁定问题

转载 作者:行者123 更新时间:2023-12-01 07:10:23 26 4
gpt4 key购买 nike

标题是我收到的错误,当我单击“加载”时,我的程序卡住了。我认为这是因为我在声明中执行声明,但从我看来,这是解决我的问题的唯一解决方案。通过加载,我只想重新填充患者列表,但要做到这一点,我还需要了解他们的条件。代码有效,底部方法是我试图修复的。我认为问题是我有 2 份声明未结,但我不确定。负载:

public void DatabaseLoad()
{
try
{
String Name = "Wayne";
String Pass= "Wayne";
String Host = "jdbc:derby://localhost:1527/Patients";
Connection con = DriverManager.getConnection( Host,Name, Pass);
PatientList.clear();


Statement stmt8 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String SQL8 = "SELECT * FROM PATIENTS";
ResultSet rs8 = stmt8.executeQuery( SQL8 );
ArrayList<PatientCondition> PatientConditions1 = new ArrayList();

while(rs8.next())
{
PatientConditions1 = LoadPatientConditions();
}

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String SQL = "SELECT * FROM PATIENTS";
ResultSet rs = stmt.executeQuery( SQL );

while(rs.next())
{
int id = (rs.getInt("ID"));
String name = (rs.getString("NAME"));
int age = (rs.getInt("AGE"));
String address = (rs.getString("ADDRESS"));
String sex = (rs.getString("SEX"));
String phone = (rs.getString("PHONE"));

Patient p = new Patient(id, name, age, address, sex, phone,
PatientConditions1);
PatientList.add(p);
}

UpdateTable();
UpdateAllViews();

DefaultListModel PatientListModel = new DefaultListModel();

for (Patient s : PatientList) {
PatientListModel.addElement(s.getAccountNumber() + "-" + s.getName());
}

PatientJList.setModel(PatientListModel);

}

catch(SQLException err)
{
System.out.println(err.getMessage());
}


}

这是返回患者状况的 ArrayList 的方法

public ArrayList LoadPatientConditions()     
{
ArrayList<PatientCondition> PatientConditionsTemp = new ArrayList();
try
{
String Name = "Wayne";
String Pass= "Wayne";
String Host = "jdbc:derby://localhost:1527/Patients";
Connection con = DriverManager.getConnection( Host,Name, Pass);
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String SQL = "SELECT * FROM PATIENTCONDITIONS";
ResultSet rs5 = stmt.executeQuery( SQL );

int e = 0;
while(rs5.next())
{
e++;
String ConName = (rs5.getString("CONDITION"));
PatientCondition k = new PatientCondition(e,ConName);
PatientConditionsTemp.add(k);
}
}
catch(SQLException err)
{
System.out.println(err.getMessage());
}

return PatientConditionsTemp;
}

最佳答案

我也遇到了类似的问题。我正在连接到本地服务器上托管的 derby 数据库。我创建了 2 个同时连接:

  • 松鼠
  • 使用ij工具
当连接对表进行修改时,它首先获得特定表的锁。仅在 提交事务后连接才会释放此锁。因此,如果第二个连接尝试读/写同一个表,则会出现一条消息提示:
错误 40XL1:无法在请求的时间内获得锁定

要解决此问题,修改表的连接必须提交其事务。

希望这可以帮助 !

关于java - 无法在请求的时间内获得锁定问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15582682/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com