Answer the question
In order to leave comments, you need to log in
Primefaces + MySQL?
Good morning, I want to make sure that when you click on the Add button, the data is written to the database and displayed in the table with native JDBC (without hibernate, spring).
Example:
My
DAO sketches:
public static void insert() throws SQLException {
Statement st = null;
String sql = "INSERT INTO employee" + "(name, salary) " + "VALUES" + "('test', 12.0)";
try {
st = Database.getConnection().createStatement();
st.executeUpdate(sql);
}
catch (SQLException e) {
e.printStackTrace();
}
}
public void insertData() throws SQLException {
//......
}
<p:panelGrid columns="2">
<h:outputLabel value="Name: " />
<p:inputText value="#{emploee.name}"/>
<h:outputLabel value="Salary: " />
<p:inputText value="#{emploee.salary}"/>
<f:facet name="footer">
<h:commandButton value="Add" action="#{emploee.insertData()}"/>
</f:facet>
</p:panelGrid>
Answer the question
In order to leave comments, you need to log in
I got it like this.
DAO:
public static void insert(String aName, double aSalary) throws SQLException {
PreparedStatement ps = null;
try {
ps = Database.getConnection().prepareStatement("INSERT INTO table (name, salary) VALUES (?, ?)");
ps.setString(1,aName);
ps.setDouble(2, aSalary);
ps.executeUpdate();
}
catch (SQLException e) {
e.printStackTrace();
}
}
public void insertData() throws SQLException {
EmployeeDAO.insert(this.name, this.salary);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question