I am working in spring MVC with Hibernate as ORM..
In my module, I am calling a form action to store values into table. But the data is not inserted in that table. But I haven't got any errors in the log.
The code I tried with sessionFactory is,
String querys = "insert into reconcile_process (process_type,fk_last_modified_by,fk_bank_stmt_id)"
+ " values (?,?,?)";
Connection connections = sessionFactory.getCurrentSession().connection();
PreparedStatement stmt = connections.prepareStatement(querys);
stmt.setString(1, "Auto");
stmt.setInt(2, 1);
stmt.setInt(3, 251);
stmt.executeUpdate();;
connections.close();
But in the same way, I can insert the values using JDBC driver as follows,
private static final String DB_DRIVER = "org.postgresql.Driver";
private static final String DB_CONNECTION = "jdbc:postgresql://localhost:5432/xxxxx";
private static final String DB_USER = "xxxxxx";
private static final String DB_PASSWORD = "xxxxx";
Connection dbConnection = null;
PreparedStatement preparedStatement = null;
String querys = "INSERT INTO reconcile_process "
+ "(process_type,fk_last_modified_by,fk_bank_stmt_id) VALUES"
+ "(?,?,?)";
try {
dbConnection = getDBConnection();
preparedStatement = dbConnection.prepareStatement(querys);
preparedStatement.setString(1, "Type");
preparedStatement.setLong(2, 45);
preparedStatement.setLong(3, 251);
preparedStatement.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
if (preparedStatement != null) {
preparedStatement.close();
}
if (dbConnection != null) {
dbConnection.close();
}
}
private static Connection getDBConnection() {
Connection dbConnection = null;
try {
Class.forName(DB_DRIVER);
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
}
try {
dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER,
DB_PASSWORD);
return dbConnection;
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return dbConnection;
}
Can anyone point me to where the problem is?