将监听 jDateChooser 的 'textfield' 的 jTable?
jTable that will listen to jDateChooser's 'textfield'?
大家好,我正在尝试为我的系统和分析设计论文制作一个调度系统,但我在尝试 connect/bind/make jTable 听取 jDateChooser 的输入时遇到了问题。精心设计,我希望我的日程安排是这样的:
I choose a date in the jDateChooser
jTable will 'sort out' itself via the date inputted on the jDatechooser
有没有办法做到这一点?
现在我只有一个 table propertyChangelistener:
private void sched_tablePropertyChangeListener(java.beans.PropertyChangeEvent evt) {
try{
String calendar = ((JTextField)jdc.getDateEditor().getUiComponent()).getText();
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/accountsDB?zeroDateTimeBehavior=convertToNull","root","");
String query = "select * from accountsdb.schedules where Date= ?";
ps= conn.prepareStatement(query);
ps.setString(1, calendar);
ResultSet rs = ps.executeQuery();
sched_table.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (Exception e){
JOptionPane.showMessageDialog(null, e);
} finally {
if (conn != null)
try { conn.close();
} catch (SQLException ignore) {}
if (ps != null){
try {
ps.close();
} catch (SQLException ignore){}
}
}
}
不知何故,当我 运行 我的应用程序时,如果该代码块在上面,它似乎无法打开,这意味着我确实做错了什么。谁能改变或告诉我我应该做什么或者我应该从哪里开始让 jTable 听 jDatechooser 的东西?
~先谢谢那些会回答的人!~
没关系,原来我所要做的就是更改 jDateChooser 的日期格式,因为它的格式不完全相同,因此我无法从数据库中调用任何内容。如果有人对我所做的感兴趣,我就把它留在这里
private void jdcPropertyChange(java.beans.PropertyChangeEvent evt) {
try{
String d1 = ((JTextField)jdc.getDateEditor().getUiComponent()).getText();
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/accountsDB?zeroDateTimeBehavior=convertToNull","root","");
String query = "select * from accountsdb.schedules where Date= ? order by time,timezone";
ps = conn.prepareStatement(query);
ps.setString(1, d1);
ResultSet rs = ps.executeQuery();
sched_table.setModel(DbUtils.resultSetToTableModel(rs));
} catch(Exception e){
JOptionPane.showMessageDialog(null, e);
} finally {
if (conn != null) {
try { conn.close();
} catch (SQLException ignore) {}
}
if (ps != null){
try {
ps.close();
} catch (SQLException ignore){}
}
}
}
这样做的目的是,每次我从 jDateChooser(将其命名为 jdc)中选择一个日期时,table/database 都会调用该日期并将其排序。这就是我想要的。
大家好,我正在尝试为我的系统和分析设计论文制作一个调度系统,但我在尝试 connect/bind/make jTable 听取 jDateChooser 的输入时遇到了问题。精心设计,我希望我的日程安排是这样的:
I choose a date in the jDateChooser
jTable will 'sort out' itself via the date inputted on the jDatechooser
有没有办法做到这一点? 现在我只有一个 table propertyChangelistener:
private void sched_tablePropertyChangeListener(java.beans.PropertyChangeEvent evt) {
try{
String calendar = ((JTextField)jdc.getDateEditor().getUiComponent()).getText();
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/accountsDB?zeroDateTimeBehavior=convertToNull","root","");
String query = "select * from accountsdb.schedules where Date= ?";
ps= conn.prepareStatement(query);
ps.setString(1, calendar);
ResultSet rs = ps.executeQuery();
sched_table.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (Exception e){
JOptionPane.showMessageDialog(null, e);
} finally {
if (conn != null)
try { conn.close();
} catch (SQLException ignore) {}
if (ps != null){
try {
ps.close();
} catch (SQLException ignore){}
}
}
}
不知何故,当我 运行 我的应用程序时,如果该代码块在上面,它似乎无法打开,这意味着我确实做错了什么。谁能改变或告诉我我应该做什么或者我应该从哪里开始让 jTable 听 jDatechooser 的东西?
~先谢谢那些会回答的人!~
没关系,原来我所要做的就是更改 jDateChooser 的日期格式,因为它的格式不完全相同,因此我无法从数据库中调用任何内容。如果有人对我所做的感兴趣,我就把它留在这里
private void jdcPropertyChange(java.beans.PropertyChangeEvent evt) {
try{
String d1 = ((JTextField)jdc.getDateEditor().getUiComponent()).getText();
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/accountsDB?zeroDateTimeBehavior=convertToNull","root","");
String query = "select * from accountsdb.schedules where Date= ? order by time,timezone";
ps = conn.prepareStatement(query);
ps.setString(1, d1);
ResultSet rs = ps.executeQuery();
sched_table.setModel(DbUtils.resultSetToTableModel(rs));
} catch(Exception e){
JOptionPane.showMessageDialog(null, e);
} finally {
if (conn != null) {
try { conn.close();
} catch (SQLException ignore) {}
}
if (ps != null){
try {
ps.close();
} catch (SQLException ignore){}
}
}
}
这样做的目的是,每次我从 jDateChooser(将其命名为 jdc)中选择一个日期时,table/database 都会调用该日期并将其排序。这就是我想要的。