Filling Combobox from Database by Using Hibernate in Java

Populating a DropDown Menu From a SQL Database Using Hibernate in Spring MVC

You have to do first :

    ModelAndView model = new ModelAndView("index");
model.addObject("lists", list);

than

    <form:select path="list">
<form:options items="${lists}" />
</form:select>

Populate Dropdownlist with Database value in Struts 2, Hibernate

Hibernate is an ORM (Object-Relational-Mapping) framework used to map POJOs to the database schema. In your case it's Month. And because you are using annotations to map the object to table you should configure it in the hibernate.cfg.xml

<mapping class="package.to.persistence.Month" />

Without mapping the class Hibernate can't find annotations in your object.

Hibernate displaying record from JComboBox

You're re-assigning the loadName variable each time the for-loop iterates, and so you shouldn't be surprised that none of the previous data is saved. Why not instead create a DefaultComboBoxModel<E> object before the for loop, and then add to the model inside of the loop with each iteration?

JavaFX: Populating a ComboBox with data from a MySQL Database, StringConverter breaking the combobox

Answering from my comment.

You are adding a new User("username") to your data array which is why you are getting a weird String, its the ID of that particular User.

Try instead doing data.add(new User(rs.getString("username")).getUserName());, if you User class has a getUserName() method.

This may break what you are trying to do all around though, as I assume you use data more that just here. It might be best to make another variable and store you comboBox strings in that. So something like

//Init same place data is
comboString = FXCollections.observableArrayList(); //Declared somewhere else
data.add(new User(rs.getString("username")));
comboString.add(rs.getString("username"));


Related Topics



Leave a reply



Submit