import java.sql.*;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
import java.util.Vector;
public class SimpleTable extends JFrame {
public SimpleTable() {
super("Simple JTable Test");
setSize(350, 200);
//setLocation(250,300);
int ColCount;
int i;
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/employ_details","root","");
java.sql.Statement stmt= con.createStatement();
ResultSet rs= stmt.executeQuery("select * from employe_details ");
ResultSetMetaData meta =rs.getMetaData();
ColCount=meta.getColumnCount();
String s1 = null;
String s2 = null;
String s3 = null;
String s4 = null;
String s5 = null;
String s6 = null;
String s7 = null;
while (rs.next())
{
String [] record= new
String[ColCount];
for (i=0; i<ColCount; i++)
{
record[i]=rs.getString(i+1);
s1= rs.getString("Employee_ID");
s2= rs.getString("Employee_Name");
s3= rs.getString("Contact_Number");
s4 = rs.getString("Address");
s5 = rs.getString("Email");
s6 = rs.getString("dob");
s7 = rs.getString("Sex");
}
JTable jt = new JTable(new String[][]{{s1,s2,s3,s4,s5,s6,s7}}, new String[]{"Employee_ID","Employee_Name","Contact_Number","Address","Email","dob","Sex"});
JScrollPane jsp = new JScrollPane(jt);
getContentPane().add(jsp,BorderLayout.CENTER);
}}
catch (Exception e)
{
System.out.println("failure to connect " + e);
return; //(exit(1));
}
}
public static void main(String args[]) {
SimpleTable st = new SimpleTable();
st.setVisible(true);
}
}
データベースの最後の行です。 データベースのすべての行をJTableに取得する方法は?java-mysqlデータの取得問題
私はどのようにすべてのデータを保存しますか? – Rince
@Rince check update –
すべてのデータを保存する方法 – Rince