我想從數據庫表中提取數據並將其顯示在JTable
中的表中。
這裏是一些代碼,我想添加數據庫數據庫中的數據dataValues [] []
在這裏我存儲值在dataValues [][]
靜態,但我想從數據庫表中存儲dataValues[][]
值。將數據庫中的表值提取並存儲到數據值
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement();
String query = "select command_name, omc_name, to_module, start_time, end_time, status, priority, cmd_id from sync_task_table";
ResultSet resultset = statement.executeQuery(query);
dm=new DefaultTableModel();
String columnNames[] = { "Column 1", "Column 2", "Column 3" };
// Create some data
String dataValues[][] = {
{ "12", "234", "67" },
{ "-123", "43", "853" },
{ "93", "89.2", "109" },
{ "279", "9033", "3092" }
};
// Create a new table instance
table = new JTable(dataValues, columnNames);
// Add the table to a scrolling pane
scrollPane = new JScrollPane(table);
不能看到有一些關於從JDBC獲得的價值,並投入到爲TableModel – mKorbel
到底是什麼問題了嗎? –
是啊我想獲取值和存儲在dataValues [] [] ..但我不知道我在dataValues [] [] becoz中添加值我不是gud二維數組請幫助我 – user2508209