agora inbox for pljava-dev@postgresql.org  
help / color / mirror / Atom feed
[Pljava-dev] PlJava Function-Mapping
2+ messages / 0 participants
[nested] [flat]

* [Pljava-dev] PlJava Function-Mapping
@ 2011-09-07 03:37 
  2011-09-07 06:38 ` [Pljava-dev] PlJava Function-Mapping 
  0 siblings, 1 reply; 2+ messages in thread

From:  @ 2011-09-07 03:37 UTC (permalink / raw)

I seem to having problems writing a PLJava function-mapping. Consider the
code examples shown below that demonstrates in a very simple manner the
problem I am having:

*Consider I define the following PL Java function in PostgreSQL:*

CREATE OR REPLACE FUNCTION stringtest(character varying)
RETURNS tuple AS
  'test.Org.getString'
LANGUAGE java VOLATILE

SELECT * FROM teststring(?hello?);

*The in Java I have:*

public class Org {

    public static boolean getString(String input, ResultSet receiver)
    throws SQLException{

        String input_ = Common.getParam2();
        receiver.updateString("first", input);
        receiver.updateString("second", input_);

        return true;
    }
}

public class Common {

    public static String getParam2(){
        try {
            Class.forName("org.postgresql.Driver");
            Connection connection = DriverManager.getConnection(
                    "jdbc:postgresql://localhost:5432/mydb",
                     ?username",
                     ?password");
            ResultSet rs = connection.createStatement().executeQuery(
                     "select id FROM events"  
            );
            if(rs.next())
                 return rs.getString("id");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    return null;
    }

}

So now the problem is: if I don?t call /Common.param2()/ and instead just
hard-code some dummy-string everything works fine. But when I try calling
some other function, such as /.getParam2()/, I get an error, as follows:

/    ERROR:  java.lang.NoClassDefFoundError: Could not initialize class
java.net.InetAddress/

Clearly the above is just the standard SDK, so this is really confusing me
as to why it is happening.

Any help would be much appreciated.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/PlJava-Function-Mapping-tp4777098p4777098.html
Sent from the PL/Java mailing list archive at Nabble.com.




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* [Pljava-dev] PlJava Function-Mapping
  2011-09-07 03:37 [Pljava-dev] PlJava Function-Mapping 
@ 2011-09-07 06:38 ` 
  0 siblings, 0 replies; 2+ messages in thread

From:  @ 2011-09-07 06:38 UTC (permalink / raw)

Hi Larry

I have not tested your code yet, but I think you have to use:

DriverManager.getConnection("jdbc:default:connection").createStatement();
instead of connecting like a normal jdbc connection.

see also
http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/pljava/org.postgresql.pljava/docs/userguide.html?rev=1.1...
_

Cheers
Chris


2011/9/7 Larry <l.paige at live.com>

> I seem to having problems writing a PLJava function-mapping. Consider the
> code examples shown below that demonstrates in a very simple manner the
> problem I am having:
>
> *Consider I define the following PL Java function in PostgreSQL:*
>
> CREATE OR REPLACE FUNCTION stringtest(character varying)
> RETURNS tuple AS
>  'test.Org.getString'
> LANGUAGE java VOLATILE
>
> SELECT * FROM teststring(?hello?);
>
> *The in Java I have:*
>
> public class Org {
>
>    public static boolean getString(String input, ResultSet receiver)
>    throws SQLException{
>
>        String input_ = Common.getParam2();
>        receiver.updateString("first", input);
>        receiver.updateString("second", input_);
>
>        return true;
>    }
> }
>
> public class Common {
>
>    public static String getParam2(){
>        try {
>            Class.forName("org.postgresql.Driver");
>            Connection connection = DriverManager.getConnection(
>                    "jdbc:postgresql://localhost:5432/mydb",
>                     ?username",
>                     ?password");
>            ResultSet rs = connection.createStatement().executeQuery(
>                     "select id FROM events"
>            );
>            if(rs.next())
>                 return rs.getString("id");
>        } catch (Exception ex) {
>            ex.printStackTrace();
>        }
>    return null;
>    }
>
> }
>
> So now the problem is: if I don?t call /Common.param2()/ and instead just
> hard-code some dummy-string everything works fine. But when I try calling
> some other function, such as /.getParam2()/, I get an error, as follows:
>
> /    ERROR:  java.lang.NoClassDefFoundError: Could not initialize class
> java.net.InetAddress/
>
> Clearly the above is just the standard SDK, so this is really confusing me
> as to why it is happening.
>
> Any help would be much appreciated.
>
> --
> View this message in context:
> http://postgresql.1045698.n5.nabble.com/PlJava-Function-Mapping-tp4777098p4777098.html
> Sent from the PL/Java mailing list archive at Nabble.com.
> _______________________________________________
> Pljava-dev mailing list
> Pljava-dev at pgfoundry.org
> http://pgfoundry.org/mailman/listinfo/pljava-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20110907/a1e795d4/attachment.html;



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2011-09-07 06:38 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-07 03:37 [Pljava-dev] PlJava Function-Mapping 
2011-09-07 06:38 ` 

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox