From derby-user-return-12540-apmail-db-derby-user-archive=db.apache.org@db.apache.org Tue Mar 30 12:12:54 2010 Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 61099 invoked from network); 30 Mar 2010 12:12:54 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 30 Mar 2010 12:12:54 -0000 Received: (qmail 88641 invoked by uid 500); 30 Mar 2010 12:12:53 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 88567 invoked by uid 500); 30 Mar 2010 12:12:52 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 88560 invoked by uid 99); 30 Mar 2010 12:12:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Mar 2010 12:12:52 +0000 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [87.241.53.234] (HELO silmasoftware.com) (87.241.53.234) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Mar 2010 12:12:44 +0000 Received: from PALUMBOXP by silmasoftware.com (MDaemon.Standard.v8.1.3.R) with ESMTP id md50001056816.msg for ; Tue, 30 Mar 2010 14:07:18 +0200 From: "Flavio Palumbo" To: "Derby Discussion" Subject: R: calling ASTParser repeatedly rises an exception Date: Tue, 30 Mar 2010 14:09:32 +0200 Message-ID: <2E96697064D149EE832936287CE4E46B@PALUMBOXP> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 In-Reply-To: X-Authenticated-Sender: f.palumbo@silmasoftware.com X-MDRemoteIP: 10.0.0.82 X-Return-Path: f.palumbo@silmasoftware.com X-MDaemon-Deliver-To: derby-user@db.apache.org X-Virus-Checked: Checked by ClamAV on apache.org Hi all, i made a little bit more investigation on original ASTParser code and i discover something really strange : - calling repeatedly the original ASTParser code works fine - if i wrap the body of the parsing with try/catch block, original ASTParser code, i get the exception menthioned In my mind i think that the point is understanding in which cases this exception is rised. I provide below the classes code Any hint would be appreciated Flavio ---------------------------------------------------------------------------- -------------------------- public class MyRun { public static void main(String[] args) { String[] a = {"insert into flavio.anadiv (?,?,?,?,?,?,?,?,?,?,?,?)", "insert into eurofile.tdepro (dpcdst, dpcdme, dpcdpr) values(?, ?, ?)"}; for (int i = 0; i < a.length; i++) { ASTParser astParser = new ASTParser(); String[] aa = new String[1]; aa[0] = a[i]; try { astParser.execute(aa); } catch (Throwable t) { System.out.println("MyRun - errore - " + t); } } System.exit(0); } } ---------------------------------------------------------------------------- -------------------------------- import java.io.*; import java.sql.*; import org.apache.derby.iapi.services.context.ContextManager; import org.apache.derby.iapi.services.sanity.SanityManager; import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; import org.apache.derby.impl.jdbc.EmbedConnection; import org.apache.derby.impl.sql.compile.QueryTreeNode; public class ASTParser { public static final String DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver"; public static final String CONNECTION_URL = "jdbc:derby:memory:dummy;create=true"; public static final String DERBY_DEBUG_SETTING = "derby.debug.true"; public static final String STOP_AFTER_PARSING = "StopAfterParsing"; public static final String STOPPED_AFTER_PARSING = "42Z55"; public static final String SHUTDOWN_URL = "jdbc:derby:;shutdown=true"; public static final String LANG_CONNECTION = "LanguageConnectionContext"; private PrintStream _printStream = System.out; public static void main(String[] args) throws Exception { ASTParser astParser = new ASTParser(); String[] a = {"insert into eurofile.tdepro (dpcdst, dpcdme, dpcdpr) values(?, ?, ?)"}; astParser.execute(a); } public void execute(String[] args) throws Exception { try { // <------- this is the try/catch block that seems to break the program System.setProperty(DERBY_DEBUG_SETTING, STOP_AFTER_PARSING); Class.forName(DRIVER_NAME); String text = args[ 0]; Connection conn = DriverManager.getConnection(CONNECTION_URL); PreparedStatement ps = null; println("Parsing:\n" + text); try { ps = conn.prepareStatement(text); } catch (SQLException se) { String sqlState = se.getSQLState(); if (!STOPPED_AFTER_PARSING.equals(sqlState)) { throw se; } } ContextManager contextManager = ((EmbedConnection) conn).getContextManager(); LanguageConnectionContext lcc = (LanguageConnectionContext) contextManager.getContext(LANG_CONNECTION); QueryTreeNode queryTree = (QueryTreeNode) lcc.getLastQueryTree(); SanityManager.SET_DEBUG_STREAM(new PrintWriter(_printStream)); queryTree.treePrint(); } catch (Throwable t) { System.out.println("ASTParser - errore " + t); } boolean gotSQLExc = false; try { DriverManager.getConnection(SHUTDOWN_URL); } catch (SQLException se) { if (se.getSQLState().equals("XJ015")) { gotSQLExc = true; } } if (!gotSQLExc) { System.out.println("Database did not shut down normally"); } else { System.out.println("Database shut down normally"); } } public void println(String text) { _printStream.println(text); } } > -----Messaggio originale----- > Da: Flavio Palumbo [mailto:f.palumbo@silmasoftware.com] > Inviato: lunedì 29 marzo 2010 16.27 > A: derby-user@db.apache.org > Oggetto: calling ASTParser repeatedly rises an exception > > > Hi all, > i'trying plug into an application some code derived from ASTParser. > > This code is inserted in a single class that does the parsing > (say class A). > > The parsing can be called many time from a main class that > everytime creates > a new class A. > > The strange behavior i found is that, the first time i create the class A, > the parsing is done with no problems, while from the second time i get a > "java.sql.SQLException: org.apache.derby.jdbc.EmbeddedDriver is not > registered with the JDBC driver manager" everytime. > > This happens when the class executes "Connection conn = > DriverManager.getConnection(CONNECTION_URL);" > > I'm sure that everytime the class A is called i shut down the connection > properly. > > Can somebody help me to figure out why this happens ? > > thanks a lot > Flavio > > > ----------------------------------------------------------- > Il presente messaggio non costituisce un impegno contrattuale tra > SILMA S.r.l. ed il destinatario. > Le opinioni ivi espresse sono quelle dell'autore. > SILMA S.r.l. non assume alcuna responsabilita riguardo al > contenuto del presente messaggio. > Il messaggio è destinato esclusivamente al destinatario. > Il contenuto e gli allegati sono da considerarsi di natura confidenziale > > Nel caso abbiate ricevuto il presente messaggio per errore siete > pregati di comunicarlo > alla casella segreteria@silmasoftware.com. > ----------------------------------------------------------- Il presente messaggio non costituisce un impegno contrattuale tra SILMA S.r.l. ed il destinatario. Le opinioni ivi espresse sono quelle dell'autore. SILMA S.r.l. non assume alcuna responsabilita riguardo al contenuto del presente messaggio. Il messaggio è destinato esclusivamente al destinatario. Il contenuto e gli allegati sono da considerarsi di natura confidenziale Nel caso abbiate ricevuto il presente messaggio per errore siete pregati di comunicarlo alla casella segreteria@silmasoftware.com.