有人可以为我提供一个示例或教程,说明如何使用 GUI 从 JTable 中的 mysql 数据库导入数据。我尝试寻找一个例子,但没有找到任何东西。
最佳答案
希望我们可以解决这个问题
Connection db = DriverManager.getConnection( jdbc:mysql://192.168.0.3:3306,<user>,<password>);
Statement stmt = db.createStatement();
PreparedStatement psmt = con.prepareStatement("SELECT * FROM DB");
ResultSet rs = psmt.executeQuery();
// get column names
int len = rs.getMetaData().getColumnCount();
Vector cols= new Vector(len);
for(int i=1; i<=len; i++) // Note starting at 1
cols.add(rs.getMetaData().getColumnName(i));
// Add Data
Vector data = new Vector();
while(rs.next())
{
Vector row; = new Vector(len);
for(int i=1; i<=len; i++)
{
row.add(rs.getString(i));
}
data.add(row);
}
// Now create the table
JTable table = new JTable(data, cols);
关于java - JTable swing导入数据库sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9603897/