Foros de discusión

How can Query in database table whitout service builder?

thumbnail
habib zare, modificado hace 11 años.

How can Query in database table whitout service builder?

Junior Member Mensajes: 58 Fecha de incorporación: 28/10/12 Mensajes recientes
There is no entity(there is no service builder) in my portlet but i want to select or insert data in any table of database.

How can i do that?
thumbnail
Subhash Pavuskar, modificado hace 11 años.

RE: How can Query in database table whitout service builder?

Regular Member Mensajes: 234 Fecha de incorporación: 13/03/12 Mensajes recientes
Hi habib zare ,

You can do this by manual JDBC connection!! but its having lots of disadvantage !!
For Ex:

<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
	String userid=request.getParameter("user"); 
	session.putValue("userid",userid); 
	String pwd=request.getParameter("pwd"); 
	Class.forName("com.mysql.jdbc.Driver"); 
	java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root"); 
	Statement st= con.createStatement(); 
	ResultSet rs=st.executeQuery("select * from users where user_id='"+userid+"'"); 

	if(rs.next()) 
	{ 
		if(rs.getString(2).equals(pwd)) 
		{ 
			out.println("welcome"+userid); 
		} 
		else 
		{ 
			out.println("Invalid password try again"); 
		} 
	}  
%>
thumbnail
habib zare, modificado hace 11 años.

RE: How can Query in database table whitout service builder?

Junior Member Mensajes: 58 Fecha de incorporación: 28/10/12 Mensajes recientes
Thanks Subhash.

Can I do this by custom sql or dynamic query?
thumbnail
Subhash Pavuskar, modificado hace 11 años.

RE: How can Query in database table whitout service builder?

Regular Member Mensajes: 234 Fecha de incorporación: 13/03/12 Mensajes recientes
Habib Zare:

Can I do this by custom sql or dynamic query?


I dint get your question !!
thumbnail
Habib Zare, modificado hace 11 años.

RE: How can Query in database table whitout service builder?

Junior Member Mensajes: 58 Fecha de incorporación: 28/10/12 Mensajes recientes
Subhash Pavuskar:
Habib Zare:

Can I do this by custom sql or dynamic query?


I dint get your question !!


Can i insert to extisting table by custom-sql or dynamic query?(There is no service.)
thumbnail
Subhash Pavuskar, modificado hace 11 años.

RE: How can Query in database table whitout service builder?

Regular Member Mensajes: 234 Fecha de incorporación: 13/03/12 Mensajes recientes
Hi

Pls have a look on this thread !!
http://www.liferay.com/community/forums/-/message_boards/message/12569596
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: How can Query in database table whitout service builder?

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
You can just a method in Impl class corresponding to the database table class. If it's a liferay table, you probably won't have problem.

Example
UserLocalServiceImpl.dynamicQuery()
thumbnail
Habib Zare, modificado hace 11 años.

RE: How can Query in database table whitout service builder?

Junior Member Mensajes: 58 Fecha de incorporación: 28/10/12 Mensajes recientes
Thanks Hitoshi.

but I added the table in database. table is not liferay table.
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: How can Query in database table whitout service builder?

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
but I added the table in database. table is not liferay table.


And you don't want to use service builder. So did you code dynamicquery and customquery methods yourself? If you did, you can just call that.
thumbnail
Habib Zare, modificado hace 11 años.

RE: How can Query in database table whitout service builder?

Junior Member Mensajes: 58 Fecha de incorporación: 28/10/12 Mensajes recientes
Yes Hitoshi.

I can call customquery in my finderimpl class when i use servicebuilder like :

 public Object findByName( String name)
		{


		Session session = null;

		
	        session = openSession();

                String sql = CustomSQLUtil.get("com.habib.findByName");

		SQLQuery q = session.createSQLQuery(sql);

		QueryPos qPos = QueryPos.getInstance(q);

		return q.list(true);

               }


but if there is no servicebuilder ,i can`t.

i can`t use openSession().

i want any example to learn.

thx.
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: How can Query in database table whitout service builder?

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
but if there is no servicebuilder ,i can`t.

i can`t use openSession().


That's simply because you didn't create a method. Create it.
How else did you think you can call on a function without generating it or creating it yourself.