Using Bind Variables in query
How to use bind variables
//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
No comments:
Post a Comment