Fórum

How can Query in database table whitout service builder?

thumbnail
habib zare, modificado 11 Anos atrás.

How can Query in database table whitout service builder?

Junior Member Postagens: 58 Data de Entrada: 28/10/12 Postagens Recentes
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 11 Anos atrás.

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

Regular Member Postagens: 234 Data de Entrada: 13/03/12 Postagens Recentes
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 11 Anos atrás.

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

Junior Member Postagens: 58 Data de Entrada: 28/10/12 Postagens Recentes
Thanks Subhash.

Can I do this by custom sql or dynamic query?
thumbnail
Subhash Pavuskar, modificado 11 Anos atrás.

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

Regular Member Postagens: 234 Data de Entrada: 13/03/12 Postagens Recentes
Habib Zare:

Can I do this by custom sql or dynamic query?


I dint get your question !!
thumbnail
Habib Zare, modificado 11 Anos atrás.

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

Junior Member Postagens: 58 Data de Entrada: 28/10/12 Postagens Recentes
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 11 Anos atrás.

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

Regular Member Postagens: 234 Data de Entrada: 13/03/12 Postagens Recentes
Hi

Pls have a look on this thread !!
http://www.liferay.com/community/forums/-/message_boards/message/12569596
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

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

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
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 11 Anos atrás.

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

Junior Member Postagens: 58 Data de Entrada: 28/10/12 Postagens Recentes
Thanks Hitoshi.

but I added the table in database. table is not liferay table.
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

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

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
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 11 Anos atrás.

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

Junior Member Postagens: 58 Data de Entrada: 28/10/12 Postagens Recentes
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 11 Anos atrás.

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

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
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.