This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Introduction and a question

1 reply
Steve Sobczak
Joined: 2009-03-23,
User offline. Last seen 42 years 45 weeks ago.
Hello all,

After enough podcasts, Scala concepts are finally starting to click in my thoughts and NetBeans is running great (not so great with Eclipse plugin).  I've made lots of progress, having just started using the language last week, but one error is complicating my learning.

I have this JDBC sample running: http://scala.sygneca.com/code/simplifying-jdbc

Except, this line:
implicit def str2RichPrepared(s: String)(implicit conn: Connection): RichPreparedStatement = conn prepareStatement(s);

and this usage:
for (val person3 <- "select * from person" <<! (rs => Person(rs,rs,rs)))
            println(person3.toXML);

are giving me:
found   : java.sql.PreparedStatement
required: RichSQL.RichPreparedStatement
Note: implicit method rich2St is not applicable here
because it comes after the application point and it lacks an explicit result type
    implicit def str2RichPrepared(s: String)(implicit conn: Connection): RichPreparedStatement = conn prepareStatement(s);

Does anyone have any analysis to offer, please?

Steve Sobczak


DRMacIver
Joined: 2008-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Introduction and a question

2009/3/23 Steve Sobczak :
> Hello all,
>
> After enough podcasts, Scala concepts are finally starting to click in my
> thoughts and NetBeans is running great (not so great with Eclipse plugin).
> I've made lots of progress, having just started using the language last
> week, but one error is complicating my learning.
>
> I have this JDBC sample running:
> http://scala.sygneca.com/code/simplifying-jdbc
>
> Except, this line:
> implicit def str2RichPrepared(s: String)(implicit conn: Connection):
> RichPreparedStatement = conn prepareStatement(s);
>
> and this usage:
> for (val person3 <- "select * from person" < Person(rs,rs,rs)))
>             println(person3.toXML);
>
> are giving me:
> found   : java.sql.PreparedStatement
> required: RichSQL.RichPreparedStatement
> Note: implicit method rich2St is not applicable here
> because it comes after the application point and it lacks an explicit result
> type
>     implicit def str2RichPrepared(s: String)(implicit conn: Connection):
> RichPreparedStatement = conn prepareStatement(s);
>
> Does anyone have any analysis to offer, please?

Well, it might help you to note that the implicit method rich2St is
not applicable here because it comes after the application point and
it lacks an explicit result type.

So, in order to fix the problem, you could give it an explicit result
type or put it before the application point.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland