myeclipse中拖拽了一个jTable 当点击jButton时在jTable中显示数据库中的信息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了myeclipse中拖拽了一个jTable 当点击jButton时在jTable中显示数据库中的信息相关的知识,希望对你有一定的参考价值。
import java.net.ServerSocket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/*
* 表.java
*
* Created on __DATE__, __TIME__
*/
/**
*
* @author __USER__
*/
public class 表 extends javax.swing.JFrame
/** Creates new form 表 */
public 表()
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.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents()
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object[][] null, null, null, null, null ,
null, null, null, null, null ,
null, null, null, null, null ,
null, null, null, null, null , new String[]
"用户ID", "用户名称", "用户密码", "用户权限", "备注" )
boolean[] canEdit = new boolean[] false, false, false, false,
false ;
public boolean isCellEditable(int rowIndex, int columnIndex)
return canEdit[columnIndex];
);
jScrollPane1.setViewportView(jTable1);
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
try
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;DatebaseName = 邮局订报系统",
"heart", "123");
Statement stmt = conn
.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt
.executeQuery("select * from 邮局订报系统.dbo.Userinfo ");
while (rs.next())
?????
?????
catch (Exception ex)
ex.printStackTrace();
new javax.swing.table.DefaultTableModel追问
能不能具体点啊?
以上是关于myeclipse中拖拽了一个jTable 当点击jButton时在jTable中显示数据库中的信息的主要内容,如果未能解决你的问题,请参考以下文章