java jtable如何使用rs2xml
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27679867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jtable how to use rs2xml
提问by Vivian Maya
I'am currently newbie at java, and I've been searching for a effective way to put database informations to jtable and I heard about rs2xml. I really want to learn this because other methods makes me confuse and gives me headache.
我目前是 java 的新手,我一直在寻找一种将数据库信息放入 jtable 的有效方法,我听说过 rs2xml。我真的很想学习这个,因为其他方法让我感到困惑并让我头疼。
Does anyone know how to use it effectively ? And if you don't mind can you explain with a simple code.
有谁知道如何有效地使用它?如果你不介意,你可以用一个简单的代码来解释。
Thanks in advance.
提前致谢。
采纳答案by Mohammed Housseyn Taleb
import net.proteanit.sql.DbUtils;
try {
st = conn.createStatement();
st.executeQuery(q);
ResultSet rs = st.executeQuery(q);
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex);
} finally {
try {
rs.close();
} catch (SQLException e) { /* ignore */
}
try {
st.close();
} catch (SQLException e) { /* ignore */
}
}
that a sample of use video tutorial
使用视频教程的示例
回答by Mohammed Housseyn Taleb
- //Before this add rs2XML.jar in your project properties by adding //addLibray //option
- //在此之前通过添加 //addLibray //option 在您的项目属性中添加 rs2XML.jar
private void b2ActionPerformed(java.awt.event.ActionEvent evt) { int id = 0; String name = ""; String mobile = ""; String email = ""; String flat = ""; String query=""; Connection con; try{ String query= "select * from apt" con=DBconnect.ConnectDB();//it's a class the connection properties are defined here PreparedStatement ps; ps = con.prepareStatement(query); ResultSet rs = ps.executeQuery(); jTable1.setModel(DbUtils.resultSetToTableModel(rs)); } }catch(Exception ee){ ee.printStackTrace(); } }