[Pljava-dev] PlJava Function-Mapping

Lists: pljava-dev
From: l(dot)paige at live(dot)com (Larry)
To:
Subject: [Pljava-dev] PlJava Function-Mapping
Date: 2011-09-07 03:37:24
Message-ID: 1315366644852-4777098.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pljava-dev

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.


From: vorarlberger at gmail(dot)com (Vorarlberger)
To:
Subject: [Pljava-dev] PlJava Function-Mapping
Date: 2011-09-07 06:38:58
Message-ID: CALtUeZaOBws7onYNt7iw1PK+K9YZOW9JYMgOrAoEHQgKOoFEVA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pljava-dev

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.15#Using_JDBC
_

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>