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;
}
}