Showing posts with label session. Show all posts
Showing posts with label session. Show all posts

Thursday, October 4

Using Bind Variables in query



//Following code helps to use bind variables in java and Oracle query

import org.hibernate.SessionFactory;

private SessionFactory sessionFactory;

public void method() {
      Session session = null;
      String  studentId = “R16”;
            try {
            session = sessionFactory.openSession();
String sql_select_query = "select name, class, age from class_table where id = :studentId";
            Query query = session.createSQLQuery(sql_select_query);
            query.setString("studentId", studentId);
                  List<Object[]> list = query.list();
      }          
 }

//Use catch or finally block with the above code
//Also use hibernate .jar file to implement above code

Monday, October 1

Creating / Using session : Java Web Project



// NameSpace imports

import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
/* Use openSymphony .jar for above import


//Declaration of Session
private Map session;

//Create setter getter

session = ActionContext.getContext().getSession();

//Use session.put & session.get
session.put(“Id”,userID );
String userId = (String)session.get(“Id”);