You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Frans Verster <fv...@gmail.com> on 2013/12/07 11:08:19 UTC

Java DB / Apache Derby Table Functions,current user?

Hi Guys and Girls,

Sorry to bother.. I am making some Java DB / Apache Derby Table Functions,
working very nice. I need to know the user querying the function to return
only his/her items. How can I get the session/login/current user?

Thanks in advance

Frans

Re: Java DB / Apache Derby Table Functions,current user?

Posted by Knut Anders Hatlen <kn...@oracle.com>.
Frans Verster <fv...@gmail.com> writes:

> Hi Guys and Girls,
>
> Sorry to bother.. I am making some Java DB / Apache Derby Table
> Functions, working very nice. I need to know the user querying the
> function to return only his/her items. How can I get the
> session/login/current user?

Hi Frans,

The SESSION_USER function returns the name of the user that invoked the
table function. Something like this should do the trick, I think:

    public static ResultSet tablefunc() throws SQLException {
        String user;
        try (Connection c = DriverManager.getConnection("jdbc:default:connection");
                Statement stmt = c.createStatement();
                ResultSet rs = stmt.executeQuery("values session_user")) {
            rs.next();
            user = rs.getString(1);
        }

        return createResultSetForUser(user);
    }

Hope this helps,

-- 
Knut Anders