How get the MySQL data in a Netbeans UI

View: New views
6 Messages — Rating Filter:   Alert me  

How get the MySQL data in a Netbeans UI

by anko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm very new to Java and Netbeans so I was happy that making an connection with my remote MySQL server was easy. Showing the data with System.out.println also.
But showing the data in a field on my form gives problems.
I have followed this example:
example
When I want to fill a textfield using this code:   jTextFieldMV.setText(rs.getString(1));
I receive this error message:
 TestMySQLUI.java:125: non-static variable jTextFieldMV cannot be referenced from a static context
            jTextFieldMV.setText(rs.getString(1));


How can i resolve this?

Re: How get the MySQL data in a Netbeans UI

by Phil Doble :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The clue is in the "static context" part of the error message.

The components on a form are all "Instance variables" - so they belong to an instance of the form - one you create using the "new" keyword. The examples use static variables and methods - these belong to the class itself. If you declare a method (or "function" if you have a background in other languages) as static, it can only use static variables - not instance variables. An example may make this clearer...

public class AClass {
   private static int aStaticVariable
   private int anInstanceVariable
   
   public static void aStaticMethod() {
      aStaticVariable = 1; // this is OK
      anInstanceVariable = 1; // this will cause a compliler error
   }

   public void anInstanceMethod() {
      aStaticVariable = 1; // this is OK
      anInstanceVariable = 1; // this is OK
   }

}

It appears that you have tried to use jTextFieldMV.setText() inside a method marked as static.

Parent Message unknown Re: How get the MySQL data in a Netbeans UI

by Wade Chandler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This list is solely for the design of the NetBeans UI...not 3rd party applications built using NB. Please use nbusers or other user lists for these type questions. See the list descriptions for which lists to use and for what.

Thanks,

Wade
 
==================
Wade Chandler, CCE
Software Engineer and Developer, Certified Forensic Computer Examiner, NetBeans Dream Team Member, and NetBeans Board Member
http://www.certified-computer-examiner.com
http://wiki.netbeans.org/wiki/view/NetBeansDreamTeam
http://www.netbeans.org

----- Original Message ----
From: anko <anko@...>
To: nbui@...
Sent: Monday, December 24, 2007 6:23:55 AM
Subject: [nbui] How get the MySQL data in a Netbeans UI



I'm very new to Java and Netbeans so I was happy that making an
 connection
with my remote MySQL server was easy. Showing the data with
System.out.println also.
But showing the data in a field on my form gives problems.
I have followed this example:
http://www.linglom.com/2007/07/14/accessing-sql-server-on-netbeans-using-jdbc-part-ii-perform-sql-operations/
example
When I want to fill a textfield using this code:  
jTextFieldMV.setText(rs.getString(1));
I receive this error message:
 TestMySQLUI.java:125: non-static variable jTextFieldMV cannot be
 referenced
from a static context
            jTextFieldMV.setText(rs.getString(1));

How can i resolve this?
--
View this message in context:
 http://www.nabble.com/How-get-the-MySQL-data-in-a-Netbeans-UI-tp14486637p14486637.html
Sent from the Netbeans - UI mailing list archive at Nabble.com.



Re: How get the MySQL data in a Netbeans UI

by anko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Wade,
Sorry for posting at the wrong list, but as far as I remember I did not choose for a specific list when I posted my question.
Besides you gave me an answer on a previos question without comment.
I'll find out how to use another list.
Thanks anyway.
Wade Chandler wrote:
This list is solely for the design of the NetBeans UI...not 3rd party applications built using NB. Please use nbusers or other user lists for these type questions. See the list descriptions for which lists to use and for what.

Thanks,

Wade
 
==================
Wade Chandler, CCE
Software Engineer and Developer, Certified Forensic Computer Examiner, NetBeans Dream Team Member, and NetBeans Board Member
http://www.certified-computer-examiner.com
http://wiki.netbeans.org/wiki/view/NetBeansDreamTeam
http://www.netbeans.org

----- Original Message ----
From: anko <anko@amulder.com>
To: nbui@netbeans.org
Sent: Monday, December 24, 2007 6:23:55 AM
Subject: [nbui] How get the MySQL data in a Netbeans UI



I'm very new to Java and Netbeans so I was happy that making an
 connection
with my remote MySQL server was easy. Showing the data with
System.out.println also.
But showing the data in a field on my form gives problems.
I have followed this example:
http://www.linglom.com/2007/07/14/accessing-sql-server-on-netbeans-using-jdbc-part-ii-perform-sql-operations/
example
When I want to fill a textfield using this code:  
jTextFieldMV.setText(rs.getString(1));
I receive this error message:
 TestMySQLUI.java:125: non-static variable jTextFieldMV cannot be
 referenced
from a static context
            jTextFieldMV.setText(rs.getString(1));

How can i resolve this?
--
View this message in context:
 http://www.nabble.com/How-get-the-MySQL-data-in-a-Netbeans-UI-tp14486637p14486637.html
Sent from the Netbeans - UI mailing list archive at Nabble.com.


Re: How get the MySQL data in a Netbeans UI

by anko :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Phil,
Your answer is clear, but I don't understand how to do it in my program. I tried to change the status of the methods in several ways, but keep having this problem or don't get any output at all.
I found another example that does work inside Netbeans but not from the command line.
But from Wade I understand this is the wrong list for my questions so I will ask somewhere else.
Phil Doble wrote:
The clue is in the "static context" part of the error message.

The components on a form are all "Instance variables" - so they belong to an instance of the form - one you create using the "new" keyword. The examples use static variables and methods - these belong to the class itself. If you declare a method (or "function" if you have a background in other languages) as static, it can only use static variables - not instance variables. An example may make this clearer...

public class AClass {
   private static int aStaticVariable
   private int anInstanceVariable
   
   public static void aStaticMethod() {
      aStaticVariable = 1; // this is OK
      anInstanceVariable = 1; // this will cause a compliler error
   }

   public void anInstanceMethod() {
      aStaticVariable = 1; // this is OK
      anInstanceVariable = 1; // this is OK
   }

}

It appears that you have tried to use jTextFieldMV.setText() inside a method marked as static.

Re: How get the MySQL data in a Netbeans UI

by sandhu@tatwaa :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

declare  "jTextFieldMV"  as static variable.... hope,u wont get error this time.






Hello Phil,
Your answer is clear, but I don't understand how to do it in my program. I tried to change the status of the methods in several ways, but keep having this problem or don't get any output at all.
I found another example that does work inside Netbeans but not from the command line.
But from Wade I understand this is the wrong list for my questions so I will ask somewhere else.
Phil Doble wrote:
The clue is in the "static context" part of the error message.

The components on a form are all "Instance variables" - so they belong to an instance of the form - one you create using the "new" keyword. The examples use static variables and methods - these belong to the class itself. If you declare a method (or "function" if you have a background in other languages) as static, it can only use static variables - not instance variables. An example may make this clearer...

public class AClass {
   private static int aStaticVariable
   private int anInstanceVariable
   
   public static void aStaticMethod() {
      aStaticVariable = 1; // this is OK
      anInstanceVariable = 1; // this will cause a compliler error
   }

   public void anInstanceMethod() {
      aStaticVariable = 1; // this is OK
      anInstanceVariable = 1; // this is OK
   }

}

It appears that you have tried to use jTextFieldMV.setText() inside a method marked as static.