I am currently working on JTable with using mysql on it. My problem is , I've tried ANY way that could be possible to refresh my JTable but none of them worked and I decided to disturb you guys if you wouldnt mind.
So, I am using vectors to get my data from MYSQL Database, and I only have a single fucntion to handle all the process.Here is my JTable creation code,
How can I make a fucntion to refresh my JTable according to this code?
Also here is the whole code of mine : http://pastebin.com/GSvjV4Va
final Vector columnNames = new Vector();
final Vector data = new Vector();
try
{
// Connect to an Access Database
driver = IniFonksiyon.iniSVNOkut(driver, "databaseBilgileri", "driver");//"com.mysql.jdbc.Driver";
url = IniFonksiyon.iniOkut(url, "databaseBilgileri", "url");//"jdbc:mysql://localhost:3306/";
userid = IniFonksiyon.iniOkut(userid, "databaseBilgileri", "kullanici");
password = IniFonksiyon.iniOkut(password, "databaseBilgileri", "sifre");
dbName = IniFonksiyon.iniOkut(dbName, "databaseBilgileri", "dbIsmi");
Class.forName( driver );
Connection connection = DriverManager.getConnection( url+dbName , userid, password );
// Read data from a table
String sql = "select * from profildb.tbl_detailed";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery( sql );
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
// Get column names
for (int i = 1; i <= columns; i++)
{
columnNames.addElement( md.getColumnName(i) );
}
// Get row data
while (rs.next())
{
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++)
{
row.addElement( rs.getObject(i) );
}
data.addElement( row );
}
rs.close();
stmt.close();
connection.close();
}
catch(Exception e)
{
System.out.println( e );
}
// Create table with database data
final JTable table = new JTable(data, columnNames)
{
/**
*
*/
private static final long serialVersionUID = 1L;
public Class getColumnClass(int column)
{
for (int row = 0; row < getRowCount(); row++)
{
Object o = getValueAt(row, column);
if (o != null)
{
return o.getClass();
}
}
return Object.class;
}
};
Thanks in advance!

New Topic/Question
Reply




MultiQuote









|