Re: [jruby-user] Using a text record from the database as a Java String?
Ariel Valentin <[email protected]> Wed, 22 Oct 2014 22:27:55 -0400
| Newsgroups | gmane.comp.lang.jruby.user |
|---|---|
| Message-ID | <CAKthdGjp92upKfXO2yU8=gDTGN3bhyp72ieonkretoNRRnaBAg@mail.gmail.com> |
Its been quite some time since I have used Rails so I am not 100% certain
but I thought ActiveRecord simply treated the DB text data type as if it
were a string in memory and everything should just "work". According to
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby:
"When calling Java from JRuby, primitive Ruby types are converted to
default boxed Java types:
Ruby TypeJava Type*"foo"**java.lang.String**1**java.lang.Long**1.0*
*java.lang.Double**true, false**java.lang.Boolean**1*
*java.math.BigInteger*
If you are running into a problem there is always "to_java" but JRuby
should already be converting the object on your behalf:
=====
irb(main):001:0> s = "ruby string"
=> "ruby string"
irb(main):002:0> j = s.to_java
=> #<Java::JavaLang::String:0x79cda784>
irb(main):006:0> j.last_index_of('r')
=> 7
HTH,
Ariel
Ariel Valentin
e-mail: [email protected]
website: http://blog.arielvalentin.com
skype: ariel.s.valentin
twitter: arielvalentin
linkedin: http://www.linkedin.com/profile/view?id=8996534
---------------------------------------
*simplicity *communication
*feedback *courage *respect
On Wed, Oct 22, 2014 at 9:27 PM, David Maxwell <[email protected]> wrote:
> I'm building a rails app where the user input is submitted to the
> database via a text field, with :text datatype. I want to take this text
> data and use java to analyse and interact with it, but to do this it
> obviously needs to be a String datatype. Is there an easy way to cast
> the text data to a String so that I can manipulate it using Java? Thanks
> :)
>
> --
> Posted via http://www.ruby-forum.com/.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>