Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 78909 invoked from network); 7 Jul 2008 21:55:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Jul 2008 21:55:22 -0000 Received: (qmail 3694 invoked by uid 500); 7 Jul 2008 21:55:23 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 3664 invoked by uid 500); 7 Jul 2008 21:55:23 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 3653 invoked by uid 99); 7 Jul 2008 21:55:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jul 2008 14:55:23 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jul 2008 21:54:39 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id A57DF234C157 for ; Mon, 7 Jul 2008 14:54:31 -0700 (PDT) Message-ID: <95515377.1215467671676.JavaMail.jira@brutus> Date: Mon, 7 Jul 2008 14:54:31 -0700 (PDT) From: "Kathey Marsden (JIRA)" To: derby-dev@db.apache.org Subject: [jira] Resolved: (DERBY-550) BLOB : java.lang.OutOfMemoryError with network JDBC driver (org.apache.derby.jdbc.ClientDriver) In-Reply-To: <445253399.1125585319674.JavaMail.jira@ajax.apache.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/DERBY-550?page=3Dcom.atlassian= .jira.plugin.system.issuetabpanels:all-tabpanel ] Kathey Marsden resolved DERBY-550. ---------------------------------- Resolution: Fixed > BLOB : java.lang.OutOfMemoryError with network JDBC driver (org.apache.de= rby.jdbc.ClientDriver) > -------------------------------------------------------------------------= ---------------------- > > Key: DERBY-550 > URL: https://issues.apache.org/jira/browse/DERBY-550 > Project: Derby > Issue Type: Bug > Components: JDBC, Network Server > Affects Versions: 10.1.1.0 > Environment: Any environment. > Reporter: Gr=C3=A9goire Dubois > Assignee: Tomohito Nakayama > Attachments: BlobOutOfMem.java > > > Using the org.apache.derby.jdbc.ClientDriver driver to access the > Derby database through network, the driver is writting all the file into = memory (RAM) before sending > it to the database. > Writting small files (smaller than 5Mo) into the database works fine, > but it is impossible to write big files (40Mo for example, or more), with= out getting the > exception java.lang.OutOfMemoryError. > The org.apache.derby.jdbc.EmbeddedDriver doesn't have this problem. > Here follows some code that creates a database, a table, and trys to writ= e a BLOB. 2 parameters are to be changed for the code to work for you : DER= BY_DBMS_PATH and FILE > import NetNoLedge.Configuration.Configs; > import org.apache.derby.drda.NetworkServerControl; > import java.net.InetAddress; > import java.io.*; > import java.sql.*; > /** > * > * @author greg > */ > public class DerbyServer_JDBC_BLOB_test { > =20 > // The unique instance of DerbyServer in the application. > private static DerbyServer_JDBC_BLOB_test derbyServer; > =20 > private NetworkServerControl server; > =20 > private static final String DERBY_JDBC_DRIVER =3D "org.apache.derby.j= dbc.ClientDriver"; > private static final String DERBY_DATABASE_NAME =3D "Test"; > =20 > // ############################################################### > // ############### SET HERE THE EXISTING PATH YOU WANT ##############= ## > // ############################################################### > private static final String DERBY_DBMS_PATH =3D "/home/greg/Database= Test"; > // ############################################################### > // ############################################################### > =20 > =20 > private static int derbyPort =3D 9157; > private static String userName =3D "user"; > private static String userPassword =3D "password"; > =20 > // ##################################################################= ################# > // ############# DEFINE HERE THE PATH TO THE FILE YOU WANT TO WRITE I= NTO THE DATABASE ########### > // ############# TRY A 100kb-3Mb FILE, AND AFTER A 40Mb OR BIGGER FIL= E ######################### > // ##################################################################= ################# > private static final File FILE =3D new File("/home/greg/01.jpg"); > // ##################################################################= ################# > // ##################################################################= ################# > =20 > /** > *

Used to test the server. > */ > public static void main(String args[]) { > try { > DerbyServer_JDBC_BLOB_test.launchServer(); > DerbyServer_JDBC_BLOB_test server =3D getUniqueInstance(); > server.start(); > System.out.println("Server started"); > =20 > // After the server has been started, launch a first connecti= on to the database to > // 1) Create the database if it doesn't exist already, > // 2) Create the tables if they don't exist already. = =20 > Class.forName(DERBY_JDBC_DRIVER).newInstance(); > Connection connection =3D DriverManager.getConnection ("jdbc:= derby://localhost:"+derbyPort+"/"+DERBY_DATABASE_NAME+";create=3Dtrue", use= rName, userPassword); > System.out.println("Network JDBC connection to Derby succeded= . Database created if not created already."); > =20 > Statement statement =3D connection.createStatement(ResultSet.= TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); > Statement statement2; > // Create the table "file" if it doesn't already exist. > String [] tableNames=3D{"file"}; > boolean exist; > String currentTable; > ResultSet result =3D statement.executeQuery("SELECT TABLENAME= FROM SYS.SYSTABLES"); > for (int i=3D0;i exist=3Dfalse; > while (result.next()){ > if (tableNames[i].equalsIgnoreCase(result.getString(1= ))) > exist=3Dtrue; > } > =20 > if (!exist) { > statement2 =3D connection.createStatement(); > statement2.execute("CREATE TABLE file (" + > "file BLOB(2G) NOT NULL)"); > connection.commit(); > } > result.beforeFirst(); > } > System.out.println("Table file created if not created already= "); > =20 > System.out.println("File insertion into BLOB"); > FileInputStream inputStream =3D new FileInputStream(FILE); > PreparedStatement preparedStatement =3D connection.prepareS= tatement("INSERT INTO file(file) VALUES (?)"); > preparedStatement.setBinaryStream(1,inputStream,(int) FILE.le= ngth()); > preparedStatement .execute(); > connection.commit(); > System.out.println("File inserted into BLOB"); > } > catch (Exception e) { > e.printStackTrace(); > } > } > =20 > /** Creates a new instance of MckoiServer > * Password is used at the database creation. It will be the database= password once created. > */ =20 > private DerbyServer_JDBC_BLOB_test() throws Exception { > System.setProperty("derby.system.home", DERBY_DBMS_PATH); > =20 > // Set the server to request an authentification. > System.setProperty("derby.authentication.provider", "BUILTIN"); > System.setProperty("derby.connection.requireAuthentication", "tru= e"); > =20 > // Create a user that can connect to Derby. > System.setProperty("derby.user."+userName, userPassword); > =20 > // Set Derby to grant full access to the created user (to all the= databases). > System.setProperty("derby.database.fullAccessUsers", userName); > =20 > //System.setProperty("derby.system.bootAll", "true"); > =20 > // See if the 9157 port is already taken. > // Change it if necessary. > boolean isPortFree =3D false; > while ( !isPortFree ) { > try { > java.net.ServerSocket serverTest =3D new java.net.ServerS= ocket(derbyPort); > serverTest.close(); > serverTest =3D null; > =20 > isPortFree =3D true; > } > catch (Exception e) { > System.out.println("Port already in use : "+derbyPort); > derbyPort++; > System.out.println("Try with port "+derbyPort); > } > } =20 > =20 > server =3D new NetworkServerControl(InetAddress.getByName("localh= ost"),derbyPort); > } > =20 > public static void launchServer() throws Exception { > derbyServer =3D new DerbyServer_JDBC_BLOB_test(); > } > =20 > public static DerbyServer_JDBC_BLOB_test getUniqueInstance() { > return derbyServer; > } > =20 > /** > *

Start the server. > */ > public void start() { > try { > server.start(null); > } > catch (Exception e) { > e.printStackTrace(System.err); > } > } > =20 > /** > *

Stop the server. > */ > public void stop() { > try { > server.shutdown(); > } > catch (Exception e) { > e.printStackTrace(System.err); > } > } > } --=20 This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.