Results 1 to 4 of 4
- 01-07-2010, 11:23 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 2
- Rep Power
- 0
Getting from database, putting into jtextfield
I have one entity class, a database package and the GUI.
Now I have problem getting the info from the database to put into the jtextfield. The red selected words are the problem I faced.
Entity:
Java Code:package forms.ui.images.Entity; import java.sql.ResultSet; import java.util.ArrayList; import forms.ui.images.database.DBController; public class Souv { public int itemLeft; public Souv() { super(); Souv(int itemLeft) { super(); this.itemLeft = itemLeft; } public int getItemLeft() { return itemLeft; } public void setItemLeft(int itemLeft) { this.itemLeft = itemLeft; } public boolean retrieveSouvenirs(){ ResultSet rs = null; DBController db = new DBController(); db.setUp("Database"); String dbQuery = "SELECT * FROM Souvenirs WHERE ItemLeft =\'" + itemLeft + "\'"; rs = db.readRequest(dbQuery); try{ if (rs.next()){ itemLeft = rs.getInt("ItemLeft"); success = true; } } catch (Exception e) { e.printStackTrace(); } db.terminate(); return success; }
GUI:
Help me!!!Java Code:package forms.ui.images; import javax.swing.JPanel; import javax.swing.JTextField; import forms.ui.images.Entity.Souv; public class Souvenirs extends JPanel { private JTextField jTextFieldLeft = null; private Souv Souvenir = null; public Souvenirs(MainFrame f) { super(); myFrame = f; initialize(); } private void initialize() { this.add(jLabelLeft, null); } private JTextField getJTextFieldLeft() { if (jTextFieldLeft == null) { jTextFieldLeft = new JTextField(); jTextFieldLeft.setBounds(new Rectangle(390, 210, 106, 31)); jTextFieldLeft.setEditable(false); Souvenir.retrieveSouvenirs(); jTextFieldLeft.setText([COLOR="Red"]Souvenir.getItemLeft().toString()[/COLOR]); } return jTextFieldLeft; } }
:confused:
- 01-07-2010, 11:37 AM #2
private Souv Souvenir = null;
You never instanciated Souvenir. And read the coding conventions, variable names start with lower case letters.Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 01-07-2010, 11:54 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 2
- Rep Power
- 0
Hello!
I have changed to
What do you mean by variable names start with lower case?Java Code:private Souv Souvenir = new Souv();
Please guide me! Thanks!
- 01-07-2010, 12:07 PM #4
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
Putting image into program
By SprayAndPray69 in forum Java AppletsReplies: 1Last Post: 02-21-2009, 03:38 AM -
how to access jTextField of one JFrame1 from JFrame2 & Modify JTextField contents
By sumit1mca in forum AWT / SwingReplies: 1Last Post: 01-30-2009, 06:44 PM -
Putting code together.
By newbee in forum New To JavaReplies: 3Last Post: 04-17-2008, 03:53 AM -
Putting your own type in a Set
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:32 PM -
Putting controls in arrays?
By Cymro in forum New To JavaReplies: 4Last Post: 02-01-2008, 06:54 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks