我想在 JTable 中显示来自 MySQL 的数据,但只显示表中的最后一行,什么也没有。请帮帮我。我知道我有一个问题,因为 jt = new JTable(data, columns) 每次为每一行创建一个新表(删除以前的)但我找不到正确的选项。
public class Test2 extends JPanel {
static final String USERNAME = "root";
static final String PASSWORD = "root";
static final String CONN_STRING = "jdbc:mysql://localhost:3306/mydbtest?useSSL=false";
JTable jt;
public Test2 () {
try {
Connection conn;
conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
Statement stmt = (Statement) conn.createStatement();
String query = "Select title, season, episode from movie";
ResultSet rs = stmt.executeQuery(query);
rs.beforeFirst();
while (rs.next()) {
String title = rs.getString("Title");
String season = rs.getString("Season"); …Run Code Online (Sandbox Code Playgroud) 我使用新闻源制作应用程序,该应用程序必须在其他 ViewController 上打开。但无法通过segue传递数据。
带新闻源的视图控制器
class SecondViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var titlenews = ""
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "newsfeedCell", for: indexPath) as! NewsFeedCell
cell.newsfeed_title.text = self.news?[indexPath.item].headline
cell.newsfeed_topic.text = self.news?[indexPath.item].topic
cell.newsfeed_time.text = timetime(from: (self.news?[indexPath.item].time)!)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("tableview")
let vc = storyboard?.instantiateViewController(withIdentifier: "newsBody") as? NewsBody
vc?.labeltext = (self.news?[indexPath.item].headline)!
print((self.news?[indexPath.item].headline)!)
self.navigationController?.pushViewController(vc!, animated: true)
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
} …Run Code Online (Sandbox Code Playgroud)