table name as parameter

2010-02-08 Thread Tom Carchrae


I am trying to load a table using a parameter to specify the table name:

  select id=selectAllFromTable parameterType=String
resultType=hashmap
select * from #{id} 
  /select

But it seems iBatis does not like this.  Any suggestions on what I am doing
wrong?  Is there a better way to load a table when I want to specify the
table name at runtime?

Thanks in advance,

Tom


-- 
View this message in context: 
http://old.nabble.com/table-name-as-parameter-tp27505213p27505213.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org



Re: table name as parameter

2010-02-08 Thread Daryl Stultz
On Mon, Feb 8, 2010 at 2:47 PM, Tom Carchrae carch...@gmail.com wrote:


 I am trying to load a table using a parameter to specify the table name:

  select id=selectAllFromTable parameterType=String
 resultType=hashmap
select * from #{id}
  /select


select * from ${id}

Daryl Stultz
_
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:da...@6degrees.com


Re: table name as parameter

2010-02-08 Thread Tom Carchrae



 I am trying to load a table using a parameter to specify the table name:

  select id=selectAllFromTable parameterType=String
 resultType=hashmap
select * from #{id}
  /select


 select * from ${id}
 

Thank you for the fast reply.  I'm now onto a new error:

ERROR main Slf4jImpl.error - Error calling Connection.prepareStatement:
java.sql.SQLSyntaxErrorException: Syntax error: Encountered null at line
1, column 15.
at 
org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown 
Source)


My mapper interface is:

  ListMap selectAllFromTable(RowBounds rowBounds, String tableName);

And I am calling it with:

 String tableName = Table;
 ListMap rows = mapper.selectAllFromTable(rowBounds, tableName);

Any further ideas?

Thanks,

Tom


-- 
View this message in context: 
http://old.nabble.com/table-name-as-parameter-tp27505213p27505434.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org



Re: table name as parameter

2010-02-08 Thread Daryl Stultz
On Mon, Feb 8, 2010 at 3:05 PM, Tom Carchrae carch...@gmail.com wrote:


 Thank you for the fast reply.  I'm now onto a new error:

 I have about 6 hours' experience with iBATIS. I just happened to know that
one.



 My mapper interface is:

  ListMap selectAllFromTable(RowBounds rowBounds, String
 tableName);


What happens if you remove rowbounds from the signature? You've specified
the parameterType as String...


-- 
Daryl Stultz
_
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:da...@6degrees.com


Re: table name as parameter

2010-02-08 Thread Nathan Maves
I would double check that you are not sending in null as the table name.


On Feb 8, 2010, at 1:05 PM, Tom Carchrae wrote:

 
 
 
 I am trying to load a table using a parameter to specify the table name:
 
 select id=selectAllFromTable parameterType=String
 resultType=hashmap
   select * from #{id}
 /select
 
 
 select * from ${id}
 
 
 Thank you for the fast reply.  I'm now onto a new error:
 
 ERROR main Slf4jImpl.error - Error calling Connection.prepareStatement:
 java.sql.SQLSyntaxErrorException: Syntax error: Encountered null at line
 1, column 15.
   at 
 org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
 Source)
   at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown 
 Source)
 
 
 My mapper interface is:
 
 ListMap selectAllFromTable(RowBounds rowBounds, String tableName);
 
 And I am calling it with:
 
 String tableName = Table;
 ListMap rows = mapper.selectAllFromTable(rowBounds, tableName);
 
 Any further ideas?
 
 Thanks,
 
 Tom
 
 
 -- 
 View this message in context: 
 http://old.nabble.com/table-name-as-parameter-tp27505213p27505434.html
 Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
 
 
 -
 To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
 For additional commands, e-mail: user-java-h...@ibatis.apache.org
 

Nathan Maves
nathan.ma...@gmail.com




-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org



Re: table name as parameter

2010-02-08 Thread Tom Carchrae



nmaves wrote:
 
 I would double check that you are not sending in null as the table name.
 

I am passing in a non-null string.  But it is definitely a problem caused by
the table name not being mapped correctly.

When i traced down inside the bowels of iBatis, it gobbles my string inside

TextSqlNode.java:38

Object value = Ognl.getValue(content, context.getBindings());

Up to this point, it's all looking so good.  Figuring out what is going on
inside the OgnlParser is, well, a touch intimidating.

Tom


-- 
View this message in context: 
http://old.nabble.com/table-name-as-parameter-tp27505213p27507728.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org



Re: table name as parameter

2010-02-08 Thread Larry Meadors
Try this:

select * from ${value}

Larry


On Mon, Feb 8, 2010 at 3:57 PM, Tom Carchrae carch...@gmail.com wrote:



 nmaves wrote:

 I would double check that you are not sending in null as the table name.


 I am passing in a non-null string.  But it is definitely a problem caused by
 the table name not being mapped correctly.

 When i traced down inside the bowels of iBatis, it gobbles my string inside

 TextSqlNode.java:38

        Object value = Ognl.getValue(content, context.getBindings());

 Up to this point, it's all looking so good.  Figuring out what is going on
 inside the OgnlParser is, well, a touch intimidating.

 Tom


 --
 View this message in context: 
 http://old.nabble.com/table-name-as-parameter-tp27505213p27507728.html
 Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
 For additional commands, e-mail: user-java-h...@ibatis.apache.org



-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org



Re: table name as parameter

2010-02-08 Thread Jeff Butler
Look at the @Param annotation.  If you pass more than one parameter to
a mapper method, them you must annotate ALL parameters:

ListMap selectAllFromTable(@Param(rowBounds) RowBounds rowBounds,
@Param(tableName) String tableName);

Whenever I forget to do this, I see errors about NULL values.

Jeff Butler

On Mon, Feb 8, 2010 at 4:57 PM, Tom Carchrae carch...@gmail.com wrote:



 nmaves wrote:

 I would double check that you are not sending in null as the table name.


 I am passing in a non-null string.  But it is definitely a problem caused by
 the table name not being mapped correctly.

 When i traced down inside the bowels of iBatis, it gobbles my string inside

 TextSqlNode.java:38

        Object value = Ognl.getValue(content, context.getBindings());

 Up to this point, it's all looking so good.  Figuring out what is going on
 inside the OgnlParser is, well, a touch intimidating.

 Tom


 --
 View this message in context: 
 http://old.nabble.com/table-name-as-parameter-tp27505213p27507728.html
 Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
 For additional commands, e-mail: user-java-h...@ibatis.apache.org



-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org



Re: table name as parameter

2010-02-08 Thread Tom Carchrae



Larry Meadors wrote:
 
 Try this:
 
 select * from ${value}
 


Excellent!  It works.  Thank you so much.  I'm guessing it somehow got
confused and thought I was passing it some OGNL. 

Tom

-- 
View this message in context: 
http://old.nabble.com/table-name-as-parameter-tp27505213p27507849.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org



Re: table name as parameter

2010-02-08 Thread Tom Carchrae



Jeff Butler-2 wrote:
 
 Look at the @Param annotation.  If you pass more than one parameter to
 a mapper method, them you must annotate ALL parameters:
 
 ListMap selectAllFromTable(@Param(rowBounds) RowBounds rowBounds,
 @Param(tableName) String tableName);
 
 Whenever I forget to do this, I see errors about NULL values.
 

This makes sense.  I had wondered what magic it was using to make the
mapping between the parameter name and the select statement.  (ie, none, or
as Larry pointed out, 'value' is a default mapping name)  

Thanks for the tip. :)  

Tom
-- 
View this message in context: 
http://old.nabble.com/table-name-as-parameter-tp27505213p27507890.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org



Re: table name as parameter

2010-02-08 Thread Jeff Butler
Well, I wasn't quite right in what I said.  RowBounds is the exception
to the rule - so if you pass more than one parameter in addition to
RowBounds, then you must use the @Param annotation.  In your case, you
don't need to annotate and value is the right default.

Jeff Butler


On Mon, Feb 8, 2010 at 5:12 PM, Tom Carchrae carch...@gmail.com wrote:



 Jeff Butler-2 wrote:

 Look at the @Param annotation.  If you pass more than one parameter to
 a mapper method, them you must annotate ALL parameters:

 ListMap selectAllFromTable(@Param(rowBounds) RowBounds rowBounds,
 @Param(tableName) String tableName);

 Whenever I forget to do this, I see errors about NULL values.


 This makes sense.  I had wondered what magic it was using to make the
 mapping between the parameter name and the select statement.  (ie, none, or
 as Larry pointed out, 'value' is a default mapping name)

 Thanks for the tip. :)

 Tom
 --
 View this message in context: 
 http://old.nabble.com/table-name-as-parameter-tp27505213p27507890.html
 Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
 For additional commands, e-mail: user-java-h...@ibatis.apache.org



-
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org