Java 现在:)我如何运行此sql语句并将rs解析为jtable?感谢程序员提供的解决方案。rs2xml.jar自动设置rs中需要的表格模型格式。@Lacrymae“rs2xml.jar自动设置rs中需要的表格模型格式”,但您是否真正理解这是如何实现的?您了解表格
Java 现在:)我如何运行此sql语句并将rs解析为jtable?感谢程序员提供的解决方案。rs2xml.jar自动设置rs中需要的表格模型格式。@Lacrymae“rs2xml.jar自动设置rs中需要的表格模型格式”,但您是否真正理解这是如何实现的?您了解表格,java,swing,netbeans,jtable,resultset,Java,Swing,Netbeans,Jtable,Resultset,现在:)我如何运行此sql语句并将rs解析为jtable?感谢程序员提供的解决方案。rs2xml.jar自动设置rs中需要的表格模型格式。@Lacrymae“rs2xml.jar自动设置rs中需要的表格模型格式”,但您是否真正理解这是如何实现的?您了解表格模型的工作原理吗。对于求职者,我会比那些知道如何制作API的人更看重这些。事实上,我不会深入调查。但许多用户都自动为jtable的结果集提供了这种解决方案。我是Java初学者,我只想一步一步地学习这个机制。@Lacrymae这取决于您,JTab
现在:)我如何运行此sql语句并将rs解析为jtable?感谢程序员提供的解决方案。rs2xml.jar自动设置rs中需要的表格模型格式。@Lacrymae“rs2xml.jar自动设置rs中需要的表格模型格式”,但您是否真正理解这是如何实现的?您了解
表格模型的工作原理吗。对于求职者,我会比那些知道如何制作API的人更看重这些。事实上,我不会深入调查。但许多用户都自动为jtable的结果集提供了这种解决方案。我是Java初学者,我只想一步一步地学习这个机制。@Lacrymae这取决于您,JTable
被Swing开发人员经常使用,并不总是显示基于SQL的结果中的数据
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package program;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;
/**
*
* @author Lacrymae_Ev
*/
public class cagbas extends javax.swing.JFrame {
private static Statement stmt;
private static Connection con;
private static final String query = "select 'aicb' as aicb,sum(dur)as dur,sum(tot)as tot from exampletable with(nolock)\n" +
"where date between '2013-07-01 00:00:00.000' and '2013-07-01 23:59:59.999'\n" +
"and id='013'";
/**
* Creates new form cagbas
*/
public cagbas() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
jScrollPane1.setViewportView(jTable1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(15, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(14, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(cagbas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(cagbas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(cagbass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(cagbas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://192.168.100.100;" + "databaseName=ExampleDB;" + "user=exampleuser;" + "password=examplepass;";
Connection con = DriverManager.getConnection(connectionUrl);
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
con.close();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, ex.toString());
}
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new cagbas().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
}
//ResultSet rs = stmt.executeQuery(query);
rs = stmt.executeQuery(query);