0

anyone have a link? I want to display data on the GUI that I made using NETBEANS..
I started learning java today,

I got error non-static variable jTextField1 cannot be referenced from a static context.

Connection con = DriverManager.getConnection("jdbc:mysql://localhost/sample", "", "");

      Statement stmt = (Statement) con.createStatement();
      String select = "SELECT name FROM sample WHERE name LIKE text";
      jTextField1.setText(select);
4
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

Error can be because JTextfield is defined outside static class "like main class". and u are accessing it in static class. In short you cant place non static variable in static functions.

0

I actually dont sure about you problem. But I have done a similar code in Neatbean. In my code I have wight the SQL statement like below.

String SQL = "SELECT * FROM sample "; 
Statement stmt =  con.createStatement();
 stmt = con.createStatement();
            rs = stmt.executeQuery(SQL);
 jTextField1.setText(rs.getString(String.valueOf("column name from SQL table")));

Thank you.

Edited by Anuradha Mandal: Multiple lines.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.