Skip to Content
avatar image
Former Member

Fail to run Tutorial Adding Persistence With JDBC (Java Web SDK)

Hi,

I followed this tutorial SAP HANA Cloud Platform and successfully run this application on HCP.

Then, I 'm trying to get data from my backend system via RFC and saving these data on HCP using Persistence With JDBC service.


I have successfully got the data(backend system information). However when I was going to save the date on HCP, there is an exception

HTTP Status 500 - org.apache.commons.dbcp.SQLNestedException: Borrow prepareStatement from pool failed.

My codes is almost the same as SAP HANA Cloud Platform, and there is only few changes. I'm sure that this problem happened when application run in red line, but I don't know why it is different from the tutorial? Can anyone help me to solve this problem?

Best Regard,

Jelly.

Here are my codes:

SystemInfoJDBCServlet:


private SystemInfoDAO sInfoDAO;

public void init() throws ServletException{

try{

InitialContext ctx = new InitialContext();

DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/DefaultDB");

sInfoDAO = new SystemInfoDAO(ds);

}catch(SQLException e){

throw new ServletException(e);

}catch(NamingException e){

throw new ServletException(e);

}

}

SystemInfoDAO :

public class SystemInfoDAO {

private DataSource dataSource;

public SystemInfoDAO(DataSource newdatasource) throws SQLException{

setDataSource(newdatasource);

}

public void setDataSource(DataSource newdatasource) throws SQLException{

this.dataSource = newdatasource;

checkTable();

}

public DataSource getDataSource(){

return dataSource;

}

public void addSystemInfo(SystemInfo systeminfo) throws SQLException{

Connection connection = dataSource.getConnection();

try{

PreparedStatement pstmt = connection.prepareStatement("INSERT INTO SYSTEMINFOS (INFO) VALUES (?)");

pstmt.setString(1, systeminfo.getInfo());

pstmt.executeUpdate();

}finally{

if(connection != null){

connection.close();}}}

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Apr 14, 2016 at 01:49 PM

    Hi,

    please check the log files of your application to find more details of the cause.

    Best regards

    Xu

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 15, 2016 at 03:07 AM

    Actually, I feel confused about this line of code:

    InitialContext ctx = new InitialContext();

    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/DefaultDB");

    personDAO = new PersonDAO(ds);

    What is the DefaultDB?

    I didn't create any schema on HCP, but after I run the sample application there is a schema created like this:

    Is this schema created by default? And is this schema the Datasource above?

    Why when I using this datasource like: systemInfoDAO = newSystemInfo(ds); I faced a HTTP500 error? I mean when I run the sample application, it works. But when I write a new code line, it won't work.

    Is there any way can I configure the DataSource?


    Capture.JPG (28.5 kB)
    Add comment
    10|10000 characters needed characters exceeded