Posts

How to call Stored Procedure in Hibernate

MySQL store procedure Here’s a MySQL store procedure, which accept a stock code parameter and return the related stock data. DELIMITER $$ CREATE PROCEDURE ` GetStocks ` ( int_stockcode varchar ( 20 ) ) BEGIN SELECT * FROM stock where stock_code = int_stockcode ; END $$ DELIMITER ; Copy In MySQL, you can simple call it with a  call  keyword : CALL GetStocks ( '7277' ) ; Copy Hibernate call store procedure In Hibernate, there are three approaches to call a database store procedure. 1. Native SQL – createSQLQuery You can use  createSQLQuery()  to call a store procedure directly. Query query = session . createSQLQuery ( "CALL GetStocks(:stockCode)" ) . addEntity ( Stock . class ) . setParameter ( "stockCode" , "7277" ) ; List result = query . list ( ) ; for ( int i = 0 ; i < result . size ( ) ; i ++ ) { Stock stock = ( Stock ) result . get ( i ) ; System . out . println ( stock ...

SOLID Principles

S.O.L.I.D stands for: S - Single Responsibility Principle O - Open/Closed Principle L - Liskov Substitution Principle I - Interface Segregation Principle D - Dependency Inversion Single responsibility principle A class should have only a single responsibility (i.e. changes to only one part of the software's specification should be able to affect the specification of the class). For example purpose of Object, HashMap, Integer classes is very clear. HashMap should not be responsible to handle TreeMap's job and Integer class should not deal with Float class's job. Open/closed principle Should be open for extension, but closed for modification. This simply means that a class should be easily extendable without modifying the class itself.   Liskov substitution principle Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program. Mean  interface should hold instance of all sub classes. Java u...

HTTP Methods

GET       1. GET is used to request data from a specified resource.       2. GET requests can be cached       3. GET requests remain in the browser history       4. GET requests can be bookmarked       5. GET requests should never be used when dealing with sensitive data       6. GET requests have length restrictions       7. GET requests is only used to request data (not modify) POST        1. POST is used to send data to a server to create/update a resource.         2. POST requests are never cached         3. POST requests do not remain in the browser history         4. POST requests cannot be bookmarked         5. POST requests have no restrictions on data length PUT         1.  PUT is used to send data to a server to create/update a reso...

SQL: DROP USER, TABLE, COLUMN, DATA

Image
DROP USER Purpose Use the  DROP   USER  statement to remove a database user and optionally remove the user's objects. When you drop a user, Oracle Database also purges all of that user's schema objects from the recycle bin. Caution:  Do not attempt to drop the users  SYS  or  SYSTEM . Doing so will corrupt your database. Prerequisites You must have the  DROP   USER  system privilege. Syntax drop_user::= user Specify the user to be dropped. Oracle Database does not drop users whose schemas contain objects unless you specify  CASCADE  or unless you first explicitly drop the user's objects. CASCADE  Specify  CASCADE  to drop all objects in the user's schema before dropping the user. You must specify this clause to drop a user whose schema contains any objects. If the user's schema contains tables, then Oracle Database drops the tables and automatically drops any referential integrity constraints on ...

SQL Joins

Image
A JOIN clause is used to combine rows from two or more tables, based on a related column between them. Different Types of SQL JOINs Here are the different types of the JOINs in SQL: (INNER) JOIN : Returns records that have matching values in both tables LEFT (OUTER) JOIN : Return all records from the left table, and the matched records from the right table RIGHT (OUTER) JOIN : Return all records from the right table, and the matched records from the left table FULL (OUTER) JOIN : Return all records when there is a match in either left or right table SQL INNER JOIN Keyword The INNER JOIN keyword selects records that have matching values in both tables. INNER JOIN Syntax SELECT   column_name(s) FROM   table1 INNER   JOIN   table2  ON   table1.column_name  =  table2.column_name ; Oracle INNER JOIN Example Let's take an example to perform Inner Join on two tables "Suppliers" and "Order1". Su...