Quantcast
Channel: SCN : All Content - SAP HANA Cloud Platform Developer Center
Viewing all articles
Browse latest Browse all 3285

Problem in getting connection for JDBC application in SAP HANA with Java Runtime environment

$
0
0

Hi guys,

 

I just started Developing JAVA EE application in in SAP HANa via eclipse plugin for SAPHANA Cloud platform

 

while i am developing an application  igo the below error

error1.JPG

it means that there is some sort of problem in establishment of connection in jdbc

 

here i am adding my code that describes how i established  my connection

package com.atumit;

 

 

import java.sql.Connection;

import java.sql.DatabaseMetaData;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

 

 

import java.util.UUID;

 

 

import javax.sql.DataSource;

 

 

/**

* Data access object encapsulating all JDBC operations for a person.

*/

public class PersonDAO {

    private DataSource dataSource;

 

 

    /**

     * Create new data access object with data source.

     */

    public PersonDAO(DataSource newDataSource) throws SQLException {

        setDataSource(newDataSource);

    }

 

 

    /**

     * Get data source which is used for the database operations.

     */

    public DataSource getDataSource() {

        return dataSource;

    }

 

 

    /**

     * Set data source to be used for the database operations.

     */

    public void setDataSource(DataSource newDataSource) throws SQLException {

        this.dataSource = newDataSource;

        checkTable();

    }

 

 

    /**

     * Add a person to the table.

     */

    public void addPerson(Person person) throws SQLException {

        Connection connection = dataSource.getConnection();

 

 

        try {

            PreparedStatement pstmt = connection

                    .prepareStatement("INSERT INTO T_PERSONS "

                    + "(ID, FIRSTNAME,MIDDLENAME, LASTNAME,LOGINNAME,PASSWORD,RETYPEPASSWORD,EMAILID,DOB,CONTACTNUM,ADDRESS,CITY,PINCODE,STATE,PANNUMBER,PASSPORTNUMBER,DRIVINGLICNUMBER MODULENAME,INSTNAMEADDR,PRIMARYSKILLS,SECONDARYSKILLS,UNDERGRAD,YEAROFPASS,UNIVNAME,PERCENTAGE) "

                    + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?,?,?,?,?,?)");

            pstmt.setString(1, UUID.randomUUID().toString());

            pstmt.setString(2, person.getFirstName());

            pstmt.setString(3, person.getMiddleName());

            pstmt.setString(4, person.getLastName());

            pstmt.setString(5, person.getLoginName());

            pstmt.setString(6, person.getPassword());

            pstmt.setString(7, person.getReTypePassowrd());

            pstmt.setString(8, person.getEmailId());

            pstmt.setString(9, person.getDob());

            pstmt.setString(10,person.getConnum());

            pstmt.setString(11,person.getAddr());

            pstmt.setString(12,person.getCity());

            pstmt.setString(13,person.getPinCode());

            pstmt.setString(14,person.getState());

            pstmt.setString(15,person.getPannum());

            pstmt.setString(16,person.getPassportNum());

            pstmt.setString(17,person.getDrivLicsNum());

            pstmt.setString(18,person.getModuleName());

            pstmt.setString(19,person.getInstAddr());

            pstmt.setString(20,person.getPrimskill());

            pstmt.setString(21,person.getSecskill());

            pstmt.setString(22,person.getUg());

            pstmt.setString(23,person.getYop());

            pstmt.setString(24,person.getInstname());

            pstmt.setString(25,person.getPercentage());

           

           

            pstmt.executeUpdate();

        } finally {

            if (connection != null) {

                connection.close();

            }

        }

    }

 

 

    /**

     * Get all persons from the table.

     */

        /**

     * Check if the person table already exists and create it if not.

     */

    private void checkTable() throws SQLException {

        Connection connection = null ;

 

 

        try {

            connection = dataSource.getConnection();

            if (!existsTable(connection)) {

                createTable(connection);

            }

        } finally {

            if (connection != null) {

                connection.close();

            }

        }

    }

 

 

    /**

     * Check if the person table already exists.

     */

    private boolean existsTable(Connection conn) throws SQLException {

        DatabaseMetaData meta = conn.getMetaData();

        ResultSet rs = meta.getTables(null, null, "T_PERSONS", null);

        while (rs.next()) {

            String name = rs.getString("TABLE_NAME");

            if (name.equals("T_PERSONS")) {

                return true;

            }

        }

        return false;

    }

 

 

    /**

     * Create the person table.

     */

    private void createTable(Connection connection) throws SQLException {

        PreparedStatement pstmt = connection

                .prepareStatement("CREATE TABLE T_PERSONS "

                        + "(ID VARCHAR(255) PRIMARY KEY NOT NULL, "

                        + "FIRSTNAME VARCHAR (255),"

                        + "MIDDLENAME VARCHAR (255),"

                        +"LASTNAME VARCHAR (255),"

                        +"LOGINNAME VARCHAR (255),"

                        + "PASSWORD VARCHAR(255), "

                        +"RETYPEPASSWORD VARCHAR(255),"

                        +"EMAILID VARCHAR(255),"

                        +"DOB STRING,"

                        +"CONTACTNUM INT ,"

                        +"ADDRESS VARCHAR(255),"

                        +"CITY VARCHAR(255),"

                        +"PINCODE INT,"

                        +"STATE CHAR(30),"

                        +"PANNUMBER VARCHAR(25),"

                        +"PASSPORTNUMBER VARCHAR(25),"

                        +"DRIVINGLICNUMBER VARCHAR(25),"

                        +"MODULENAME CHAR(30),"

                      

                        +"INSTNAMEADDR VARCHAR(40),"

                        +"PRIMARYSKILLS VARCHAR(25),"

                        +"SECONDARYSKILLS VARCHAR(25),"

                        +"UNDERGRAD VARCHAR(25),"

                        +"YEAROFPASS INT,"

                        +"UNIVNAME VARCHAR(25),"

                        +"PERCENTAGE INT,"

                        );

        pstmt.executeUpdate();

    }

}

 

and even in web.xml i added resources i.e

 

<resource-ref>

        <res-ref-name>jdbc/DefaultDB</res-ref-name>

        <res-type>javax.sql.DataSource</res-type>

    </resource-ref>

 

as i am new for deploying JDBC application into HANA Databases cany one suggest me how to resolve the above mentioned problem

 

 

Thanks&Regards

Ramu Vedula


Viewing all articles
Browse latest Browse all 3285

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>