Hi everyone,
I have created two classes, GUI class and PROVA class. When I run the DB class, it shows a frame, but not the text fields and other elements.
Can any of you notice any mistake in my code? Thanks in advance..
PROVA Class:
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class prova { Connection con; Statement st; ResultSet rs; public prova () { connect(); } public void connect() { try { String driver = "sun.jdbc.odbc.Jdbc0dbcDriver"; Class.forName(driver); String prova = "jdbc:odbc:db1"; con = DriverManager.getConnection(prova); st = con.createStatement(); String sq1 = "select * from Table1"; rs = st.executeQuery(sq1); while (rs.next()) { String fname = rs.getString("Fname"); String lname = rs.getString("Lname"); String age = rs.getString("Age"); System.out.println(fname + " " + lname + " " + age); } }catch(Exception e){ } } public static void main(String[] args) { new prova(); new gui(); } }
GUI Class
import javax.swing.*; import java.awt.*; public class gui { JFrame f; JLabel fname; JLabel lname; JLabel age; JTextField t; JTextField t1; JTextField t2; public gui() { frame(); } public void frame() { f = new JFrame (); f.setVisible(true); f.setSize (600,400); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fname = new JLabel ("First Name"); lname = new JLabel ("Last Name"); age = new JLabel ("Age"); t = new JTextField(10); t1 = new JTextField(10); t2 = new JTextField(10); JPanel p = new JPanel(); p.add(fname); p.add(t); p.add(lname); p.add(t1); p.add(age); p.add(t2); f.add(p); } }