Here it comes!

     String query = 
       "select distinct Bookmark.id "+
       "from Bookmark,Role,RoleMapper,User "+
       "where Bookmark.inFolder = ? "+
       " and RoleMapper.userName = ? "+
       "and RoleMapper.roleName=Role.roleName "+
       "and (Role.level = 5 "+
       "or Bookmark.visibility = 2 "+
       "or (Bookmark.visibility = 0 "+
       "and Bookmark.owner = ? ) "+
       "or (Bookmark.visibility = 1 "+
       "and User.userName = Bookmark.owner "+
       "and User.unit = ? )) "+
       "order by Bookmark.name";
     ps = con.prepareStatement(query);
     ps.setInt(1,inFolder.intValue());
     ps.setString(2,"'"+name+"'");
     ps.setString(3,"'"+name+"'");
     ps.setInt(4,group);
     ResultSet rs = ps.executeQuery(query);

Regards,
Pelle Poluha

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Paul D Austin
Sent: den 1 juni 2001 15:54
To: [EMAIL PROTECTED]
Subject: RE: [JBoss-user] PreparedStatement in MySQL (Syntax error!!!)


Can you post a copy of the code? 
-----Original Message----- 
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED]]On Behalf Of Pelle Poluha 
Sent: 01 June 2001 14:32 
To: [EMAIL PROTECTED] 
Subject: [JBoss-user] PreparedStatement in MySQL (Syntax error!!!) 


Hello! 
So far I haven't been able to use any PreparedStatements from my entity 
beans finder methods. All I get is an SQLException. I've used Statements 
instead. But I really want to use PreparedStatements. Now I've inserted a 
few println:s in the driver's PreparedStatement class to see what's actually

happening when I prepare a statement. This is what I get: 
[Bookmark] select distinct Bookmark.id from Bookmark,Role,RoleMapper,User 
where 
Bookmark.inFolder = ?  and RoleMapper.userName = ? and 
RoleMapper.roleName=Role. 
roleName and (Role.level = 5 or Bookmark.visibility = 2 or 
(Bookmark.visibility 
= 0 and Bookmark.owner = ? ) or (Bookmark.visibility = 1 and User.userName =

Boo 
kmark.owner and User.unit = ? )) order by Bookmark.name 
[Bookmark] java.sql.SQLException: Syntax error or access violation: You have

an 
error in your SQL syntax near '?  and RoleMapper.userName = ? and 
RoleMapper.rol 
eName=Role.roleName and (Role.l' at line 1 
[Bookmark]      at org.gjt.mm.mysql.MysqlIO.sendCommand(MysqlIO.java:497) 
[Bookmark]      at org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(MysqlIO.java:550)

[Bookmark]      at org.gjt.mm.mysql.MysqlIO.sqlQuery(MysqlIO.java:635) 
[Bookmark]      at org.gjt.mm.mysql.Connection.execSQL(Connection.java:882) 
[Bookmark]      at org.gjt.mm.mysql.Connection.execSQL(Connection.java:815) 
[Bookmark]      at 
org.gjt.mm.mysql.Statement.executeQuery(Statement.java:169) 
I've tested the SQL separetely and it works perfectly. To me it looks like 
the query gets executed before the parameters get inserted. 
Any ideas? 
I'm using JBoss 2.2.1 on Win2K. 
Regards, 
Pelle Poluha 


_______________________________________________ 
JBoss-user mailing list 
[EMAIL PROTECTED] 
http://lists.sourceforge.net/lists/listinfo/jboss-user 

winmail.dat

Reply via email to