如何在netbeans上使用jtable
我只想知道如何在netbeans上使用jtable,因为我一直在努力工作,我做不了什么好事。请帮帮我以下内容将帮助您,这是一个Netbeans项目如何在netbeans上使用jtable,netbeans,jtable,Netbeans,Jtable,我只想知道如何在netbeans上使用jtable,因为我一直在努力工作,我做不了什么好事。请帮帮我以下内容将帮助您,这是一个Netbeans项目 http://download.oracle.com/javase/tutorial/uiswing/examples/zipfiles/components-SimpleTableDemoProject.zip 你可以在谷歌上搜索教程,尤其是在YouTube上。这完全取决于你想用这张桌子做什么 如果您想将Jtable连接到数据库(如MySQL),
http://download.oracle.com/javase/tutorial/uiswing/examples/zipfiles/components-SimpleTableDemoProject.zip
你可以在谷歌上搜索教程,尤其是在YouTube上。这完全取决于你想用这张桌子做什么 如果您想将Jtable连接到数据库(如MySQL),那么下面是代码。我添加了一些评论,以便您能够轻松理解
public final void loaddbtable() {
DefaultTableModel model = (DefaultTableModel) t_View.getModel();
//declared sql below used for database selection of specific information
String sql = "Select * from tableName";
try
{
Class.forName("com.mysql.jdbc.Driver");
//connection for database
Connection conn = (Connection)
//root and username and password for access to the database
DriverManager.getConnection("jdbc:mysql://localhost:3306/DatabaseNameAsOnMySQL","root","password");
//create the statement that will be used
Statement stmt=conn.createStatement();
//executes the statement
ResultSet rs = stmt.executeQuery(sql);
//table to view data
t_View.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (Exception e)
{
//exception handled for connection to database problem or data retrieval problem
JOptionPane.showMessageDialog(null, "Error message if can't load", "Datatbase connection error", JOptionPane.ERROR_MESSAGE);
}
}
请记住,您将需要导入,例如
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import net.proteanit.sql.DbUtils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
如果希望在运行接口或使用按钮时立即加载,可以将该方法放置在构造函数中
但是要了解更多的信息和其他任何事情,请随时回复,我会帮你的
你也可以使用男性频道,因为他很好,他解释了如何做到这一点
希望这对你有所帮助