I'm trying to create to the table into my database. And this is my code.. (my db name is koneksi, and my table name is table)
private void datatable(){
DefaultTableModel tbl = new DefaultTableModel();
tbl.addColumn("Nomor Induk");
tbl.addColumn("Nama Siswa");
tbl.addColumn("Kelas");
tbl.addColumn("Jenis Kelamin");
tbl.addColumn("Nilai Harian");
tbl.addColumn("Nilai UTS");
tbl.addColumn("Nilai UAS");
tbl.addColumn("Nilai Akhir");
tbl.addColumn("Grade");
tbl.addColumn("Keterangan");
table.setModel(tbl);
try{
Statement panggil = (Statement)koneksi.gettConnection().createStatement();
ResultSet res = panggil.executeQuery("select * from table");
while(res.next()){
tbl.addRow(new Object[]{
res.getString("nis"),
res.getString("nama"),
res.getString("kelas"),
res.getString("jeniskelamin"),
res.getString("harian"),
res.getString("uts"),
res.getString("uas"),
res.getString("akhir"),
res.getString("grade"),
res.getString("ket"),
});
table.setModel(tbl);
}
}catch (Exception e)
{
JOptionPane.showMessageDialog(rootPane, e.getMessage());
}
}
And this is my koneksi.java code..
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
public class koneksi {
static Connection sambung;
public static Connection gettConnection(){
try{
sambung=DriverManager.getConnection("jdbc:mysql://localhost/koneksi","root","");
}catch (Exception e){
JOptionPane.showConfirmDialog(null,"Connection Failed");
}return sambung;
}
}
I have to trying since 5 days ago, but I'm still getting this error..
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'table' at line 1.
I still learn Java basicly. I have been to asked my software engineering teacher at school how to fix this problem, but we still can't fix it. I'm waiting for ur solution answer, thanks. :)