Results 1 to 1 of 1
- 02-18-2011, 08:40 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 1
- Rep Power
- 0
jtable and report from mysql database
Hello,
first, sorry for my bad english. I am beginner in Java. I try to make application to connect to MYSQL database and write data in it and also get some queries from it . I succeseded to write data in it,also to get some SELECT queries. For example, I have table named Proba with just three columns,for testing(ID, ime(name), prezime(surname)) . I succeseded to get SELECT * FROM Proba result in Jlist and in Combobox but I can not to get it in Jtable. I also got "select * from proba where ime like '%" + something + "%' "; query where I want to find names which contains some group of letters. I got it also in Jlist and combobox but not in table. My question is how can I write code to fill table with data from database.
My second question is how to connect jasper report with netbeans.
P.S. I got all data from table (like SELECT * FROM Proba) but I can not get data with WHERE clause. This is method for fill list and combobox with data.
public void SellectAll(Object oCombo, Object Lista) {
int status = 0;
try {
String rezultat;
String query = "SELECT * FROM proba";
Statement stmt = con.createStatement();
ResultSet rs = (ResultSet) stmt.executeQuery(query);
DefaultListModel model = new DefaultListModel();
while (rs.next()) {
rezultat = rs.getString("ime") + " " + rs.getString("prezime");
model.addElement(rezultat); // model za listu
((JComboBox) oCombo).addItem(rezultat); //combo
}
((JList) Lista).setModel(model);
} catch (SQLException e) {
e.getMessage();
}
}
public void SelectPoKriterijumu(Object oCombo, Object Lista, String pretr) {
int status = 0;
try {
String rezultat = "";
String query = "select * from proba where ime like '%" + pretr + "%' ";
Statement stmt = con.createStatement();
ResultSet rs = (ResultSet) stmt.executeQuery(query);
DefaultListModel model = new DefaultListModel();
while (rs.next()) {
rezultat = rs.getString("ime") + " " + rs.getString("prezime");
model.addElement(rezultat); // model za listu
((JComboBox) oCombo).addItem(rezultat); //combo
}
((JList) Lista).setModel(model);
} catch (SQLException e) {
e.getMessage();
}
}
Similar Threads
-
Problems using MySQL database
By Antrim in forum EclipseReplies: 1Last Post: 02-16-2011, 04:57 AM -
Mysql dynamic query, Java and Jasper report
By rajuchacha007 in forum Advanced JavaReplies: 5Last Post: 06-28-2010, 10:32 AM -
How to convert access database to mysql database?
By vrk in forum Advanced JavaReplies: 2Last Post: 02-11-2009, 04:43 AM -
Problem with jTable that is binded with a table in MySQL Database
By rajkenneth in forum NetBeansReplies: 0Last Post: 03-29-2008, 03:36 PM -
connecting to mysql database
By javagal in forum NetBeansReplies: 2Last Post: 08-04-2007, 12:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks