From: thhal at mailblocks.com (Thomas Hallgren) Date: Mon, 28 Mar 2005 23:01:21 +0200 Subject: [Pljava-dev] java.lang.SecurityException In-Reply-To: <11C803742910E84E9CDBFD344773B814759F87@srqech02.teltronics.com> References: <11C803742910E84E9CDBFD344773B814759F87@srqech02.teltronics.com> Message-ID: <424870A1.6020503@mailblocks.com> Joves Luo wrote: > Here is my code that calls the Driver. The host, database, username, > and password all come from another constants file included in the > PGtoXML package. I guess there is something wrong with the way I use > the JDBC driver. I tried removing the import java.sql.* line to stop > it from looking for the JDBC jar files. But now everything is broken > without it. Do I need to rewrite all my code to use the pljava JDBC > driver? Also why is it that this works 100% on a windows system, ( I > can even access the Linux database with the windows postgresql > function)? Thank you for your help, I would have gotten nowhere > without it. > > > Only one method needs to be rewritten AFAICS, and that's the constructor. Try this: public OWDBConnection() throws SQLException{ db = DriverManager.getConnection("jdbc:default:connection"); } That should do it. You will still use JDBC (that's just the interfaces) but now you'll use the PL/Java jdbc implementation. The connection used by PL/Java is implicit since it reflects the session of the caller of the function, hence there's need to "login". If you got your code working on a windows system you probably have an older version of PL/Java then yor setup must be slightly different there. PL/Java somehow finds the jar file of the client driver. Perhaps you had that jar file in your classpath in combination with a sligthly older version of PL/Java where security was not as tight as it is now? Eihter that, or you loaded the actual PostgreSQL client driver .jar file into the database using sqlj.install_jar. As I explained earlier, such a setup might seem to work although what really happens is that your function will behave like a client for yet another backend. I have a hard time thinking of a case when that would be desirable. Regards, Thomas Hallgren > > > package PGtoXML; > > > > import java.sql.*; > > > > public class OWDBConnection { > > private Connection db; > > public OWDBConnection() throws ClassNotFoundException, SQLException{ > > Class.forName("org.postgresql.Driver"); > > db = DriverManager.getConnection("jdbc:postgresql:" + > > > Constants.host + > > > Constants.database, > > > Constants.username, > > > Constants.password); > > } > > > > > > public ResultSet getTableNames() throws SQLException{ > > Statement sql = db.createStatement(); > > ResultSet results = sql.executeQuery > > ("select viewname from pg_views where > schemaname = 'public' and viewname like 'xml_%'"); > > return results; > > } > > > > > > public ResultSet getTableColNames (String name) throws SQLException{ > > Statement sql = db.createStatement(); > > ResultSet results = sql.executeQuery > > > ("select column_name from information_schema.columns where table_name > = '" > > + name + "' order by > ordinal_position"); > > return results; > > } > > > > > > public ResultSet getTableData (String name) throws SQLException{ > > Statement sql = db.createStatement(); > > ResultSet results = sql.executeQuery("select * from " + name); > > return results; > > } > > > > > > public static void main (String args[]) { > > try{ > > OWDBConnection demo = new OWDBConnection(); > > System.out.println("\n"); > > ResultSet tableNames = demo.getTableNames(); > > ResultSet tableData; > > > > while (tableNames.next()) { > > System.out.println(tableNames.getString(1)); > > tableData = demo.getTableData(tableNames.getString(1)); > > > for (int i=1; i<=tableData.getMetaData().getColumnCount(); > i++){ > > System.out.print("\t\t\t" + > tableData.getMetaData().getColumnName(i)); > > } > > while (tableData.next()){ > > System.out.println(); > > for (int i=1; > i<=tableData.getMetaData().getColumnCount(); i++){ > > System.out.print("\t\t\t" + > tableData.getString(i)); > > } > > } > > System.out.println("\n"); > > } > > } > > catch (Exception ex) { > > System.out.println("***Exception:\n"+ex); > > ex.printStackTrace(); > > } > > > > } > > } > >------------------------------------------------------------------------ > >_______________________________________________ >Pljava-dev mailing list >Pljava-dev at gborg.postgresql.org >http://gborg.postgresql.org/mailman/listinfo/pljava-dev > >