Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Java i Jtable i mala pomoć

[es] :: Java :: Java i Jtable i mala pomoć

[ Pregleda: 1862 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

MarkoBalkan

Član broj: 141124
Poruke: 1624
*.adsl.net.t-com.hr.



+19 Profil

icon Java i Jtable i mala pomoć17.11.2007. u 23:09 - pre 199 meseci
private void a(java.awt.event.MouseEvent evt) {


{
Vector columnNames = new Vector();
Vector data = new Vector();

try
{
// Connect to the Database

String driver = "com.mysql.jdbc.Driver";
// String url = "jdbc:odbc:Teenergy"; // if using ODBC Data Source name
String url = "jdbc:mysql://localhost:3306/database";
String userid = "root";
String password = "123";

Class.forName( driver );
Connection connection = DriverManager.getConnection( url, userid, password );

// Read data from a table

String sql = "Select * from tablica";
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();
}
catch(Exception e)
{
System.out.println( e );
}

// Create table with database data





}




}


ovo je kod koji čita iz baze na događaj miša.

sad mi još treba da rezultat povežem i prikažem u jtable-u.
znači ovaj događaj je unutar klase JFrame.
a na JFrame se nalazi Jtable i buton.
a klik na buton definira ovaj događaj iznad.
 
Odgovor na temu

bags

Član broj: 10072
Poruke: 715
*.5.14.univie.teleweb.at.



+2 Profil

icon Re: Java i Jtable i mala pomoć17.11.2007. u 23:50 - pre 199 meseci
Najlakse ti je preko Table Modela.

http://java.sun.com/docs/books...ing/components/table.html#data

U attachu imas primjer koji se mogao mozda i ljepse odraditi, ali sluzio je svrsi. :)



Free advice is seldom cheap.
Prikačeni fajlovi
 
Odgovor na temu

[es] :: Java :: Java i Jtable i mala pomoć

[ Pregleda: 1862 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.