SAP Hana Database Programming Interface-Jdbc__.net

Source: Internet
Author: User
Tags stmt
Hana JDBC Driver

After installing SAP HANA Client, the Ngdbc.jar of the installation directory is the JDBC database driver. The main note of the URL and Driver name: Driver:com.sap.db.jdbc.Driver url:jdbc:sap://ip_addr:30015 Port: 3 + instance number + code Sample

Because it's not the same as the other databases, it's directly attached to the code. Entity Classes

Package stone.hanatest;

public class Employeeentity {public
    String EmpId;
    Public String Gender;
    public int age;
    Public String EMail;
    Public String Phonenr;
    public String education;
    Public String Maritalstat;
    public int nrofchildren;
}
CRUD Code
Package stone.hanatest;

Import java.sql.*;
    public class Hanacrud {private static final String DRIVER = "Com.sap.db.jdbc.Driver";
    private static final String URL = "Jdbc:sap://192.168.2.100:30015?reconnect=true";
    Private String user = "STONE";

    Private String pwd = "hanapwd";

        Public Connection getconnection (string userid, string pwd) throws ClassNotFoundException, sqlexception{
        Class.forName (DRIVER);       
    Return Drivermanager.getconnection (URL, UserID, PWD); public void Release (Connection conn, Statement stmt) throws sqlexception{if (stmt!= null) {St
        Mt.close ();
        } if (conn!= null) {conn.close (); } public void Printemployees () throws ClassNotFoundException, sqlexception{Connection conn = this.getc
        Onnection (user, PWD); String sql = "SELECT * from STONE."
        Emp_master ";

        PreparedStatement pstmt = conn.preparestatement (sql); ResUltset rst = Pstmt.executequery ();
            while (Rst.next ()) {System.out.print (rst.getstring ("emp_id") + "|");
            System.out.print (rst.getstring ("GENDER") + "|");       

            System.out.print (rst.getstring ("EMAIL"));
        New Line System.out.println ();
    } this.release (conn, pstmt); public int Insertemployee (employeeentity emp) throws ClassNotFoundException, sqlexception{Co
        Nnection conn = this.getconnection (user, PWD); String sql = "INSERT into STONE."
        Emp_master VALUES (?,?,?,?,?,?,?,?) ";

        PreparedStatement pstmt = conn.preparestatement (sql); Pstmt.setstring (1, EMP. EMPID); Starts from 1 instead of 0 pstmt.setstring (2, EMP).
        Gender); Pstmt.setint (3, EMP.
        Age); Pstmt.setstring (4, EMP.
        EMail); Pstmt.setstring (5, EMP.
        PHONENR); Pstmt.setstring (6, EMP.
        Education); Pstmt.setstring (7, EMP.
        MARITALSTAT); Pstmt.setint (8, EMP.

        Nrofchildren);

        int count = Pstmt.executeupdate ();

        This.release (conn, pstmt);       
    return count; public int Deleteemployee (String empId) throws ClassNotFoundException, sqlexception{connecti
        On conn = this.getconnection (user, PWD); String sql = "DELETE from STONE." Emp_master WHERE emp_id=?
        ";

        PreparedStatement pstmt = conn.preparestatement (sql);
        Pstmt.setstring (1, empId);

        int count = Pstmt.executeupdate ();

        This.release (conn, pstmt);
    return count;
 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.