0

For the first time, I'm creating a Java Swing application.

I'm using Windows Builder Pro in Eclipse, and a MySQL database (already setup up).

Let's say I have a combo box, and I want (for instance) all 'name' fields from a 'certain' table appear.

How can I setup that binding? I know how to programatically handle the connection and query code, what I would like to know is how to make that binding in Eclipse.

The point is to avoid manually populate a combo box (or anything else).

Tiago
  • 1,116
  • 5
  • 25
  • 39
  • 1
    *"I honestly have no idea from where to start."* Start with a search engine, try the keywords swing+db+data-binding+tutorial. – Andrew Thompson Jun 02 '12 at 16:03
  • @AndrewThompson, There is so much information about SWT, AWT, jFaces (...) - it becomes confusing. Anyway, I edited my question because the Thor answer makes me realize that the question was not clear. – Tiago Jun 02 '12 at 16:34
  • *"There is so much information about SWT, AWT, jFaces"* If your search engine brings those to the top of a list starting with keyword 'swing', you need to find a new search engine. – Andrew Thompson Jun 02 '12 at 16:43

2 Answers2

1

This is a question covering a wide range. The short answer will be quick & dirty, not elegant and against all patterns in software engineering: Use JDBC to get the name fields

Statement stmt = null;
String query = "SELECT name FROM tableXX";

stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next())
{
   String name = rs.getString("name");
   //Fill your combo box
}

The better answer would cover

but is unfortunately overly broad and does not fit into the QA structure of stackoverflow. But with the links and keyword you will find lots of excellent articles by yourself.

Community
  • 1
  • 1
Thor
  • 6,607
  • 13
  • 62
  • 96
  • Thor I know how to perform queries and connections to the database in Java, I just don't know how can I directly do that from Eclipse, creating the binding Eclipse-Database. I edited my question to be more clear. – Tiago Jun 02 '12 at 16:35
  • You have to import the correct JDBC lib and in Eclipse (right click on file, Build, Add to Build path) and then there is no difference to the code you have implemented before. – Thor Jun 02 '12 at 16:42
  • Yes, I already added the conector to the build path. I just want to access database information inside Eclipse. Just like this tutorial (which is meant to netbeans) http://netbeans.org/kb/docs/java/gui-binding.html – Tiago Jun 02 '12 at 16:48
1

This example uses a JPA entity and controller generated by NetBeans/TopLink, but it should be possible to generate something similar using Eclipse/EclipseLlink.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045