Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Habib Zare
How can Query in database table whitout service builder?
27 de Fevereiro de 2013 08:43
Resposta

Habib Zare

Ranking: Junior Member

Mensagens: 45

Data de entrada: 28 de Outubro de 2012

Mensagens 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?
Subhash Pavuskar
RE: How can Query in database table whitout service builder?
27 de Fevereiro de 2013 09:04
Resposta

Subhash Pavuskar

Ranking: Regular Member

Mensagens: 234

Data de entrada: 12 de Março de 2012

Mensagens recentes

Hi habib zare ,

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

 1<%@ page import ="java.sql.*" %>
 2<%@ page import ="javax.sql.*" %>
 3<%
 4    String userid=request.getParameter("user");
 5    session.putValue("userid",userid);
 6    String pwd=request.getParameter("pwd");
 7    Class.forName("com.mysql.jdbc.Driver");
 8    java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
 9    Statement st= con.createStatement();
10    ResultSet rs=st.executeQuery("select * from users where user_id='"+userid+"'");
11
12    if(rs.next())
13    {
14        if(rs.getString(2).equals(pwd))
15        {
16            out.println("welcome"+userid);
17        }
18        else
19        {
20            out.println("Invalid password try again");
21        }
22    } 
23%>
Habib Zare
RE: How can Query in database table whitout service builder?
27 de Fevereiro de 2013 09:05
Resposta

Habib Zare

Ranking: Junior Member

Mensagens: 45

Data de entrada: 28 de Outubro de 2012

Mensagens recentes

Thanks Subhash.

Can I do this by custom sql or dynamic query?
Subhash Pavuskar
RE: How can Query in database table whitout service builder?
27 de Fevereiro de 2013 09:33
Resposta

Subhash Pavuskar

Ranking: Regular Member

Mensagens: 234

Data de entrada: 12 de Março de 2012

Mensagens recentes

Habib Zare:

Can I do this by custom sql or dynamic query?


I dint get your question !!
Habib Zare
RE: How can Query in database table whitout service builder?
27 de Fevereiro de 2013 09:41
Resposta

Habib Zare

Ranking: Junior Member

Mensagens: 45

Data de entrada: 28 de Outubro de 2012

Mensagens 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.)
Subhash Pavuskar
RE: How can Query in database table whitout service builder?
27 de Fevereiro de 2013 10:16
Resposta

Subhash Pavuskar

Ranking: Regular Member

Mensagens: 234

Data de entrada: 12 de Março de 2012

Mensagens recentes

Hi

Pls have a look on this thread !!
http://www.liferay.com/community/forums/-/message_boards/message/12569596
Hitoshi Ozawa
RE: How can Query in database table whitout service builder?
27 de Fevereiro de 2013 13:17
Resposta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensagens: 7949

Data de entrada: 23 de Março de 2010

Mensagens 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()
Habib Zare
RE: How can Query in database table whitout service builder?
27 de Fevereiro de 2013 19:52
Resposta

Habib Zare

Ranking: Junior Member

Mensagens: 45

Data de entrada: 28 de Outubro de 2012

Mensagens recentes

Thanks Hitoshi.

but I added the table in database. table is not liferay table.
Hitoshi Ozawa
RE: How can Query in database table whitout service builder?
27 de Fevereiro de 2013 22:15
Resposta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensagens: 7949

Data de entrada: 23 de Março de 2010

Mensagens 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.
Habib Zare
RE: How can Query in database table whitout service builder?
27 de Fevereiro de 2013 23:08
Resposta

Habib Zare

Ranking: Junior Member

Mensagens: 45

Data de entrada: 28 de Outubro de 2012

Mensagens recentes

Yes Hitoshi.

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

 1 public Object findByName( String name)
 2        {
 3
 4
 5        Session session = null;
 6
 7       
 8            session = openSession();
 9
10                String sql = CustomSQLUtil.get("com.habib.findByName");
11
12        SQLQuery q = session.createSQLQuery(sql);
13
14        QueryPos qPos = QueryPos.getInstance(q);
15
16        return q.list(true);
17
18               }


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

i can`t use openSession().

i want any example to learn.

thx.
Hitoshi Ozawa
RE: How can Query in database table whitout service builder?
28 de Fevereiro de 2013 05:15
Resposta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensagens: 7949

Data de entrada: 23 de Março de 2010

Mensagens 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.