Hello all,

I found a way to make it work when running from exported JAR.
In my DB_URL build from my getResource() function, I replace() "file:" with 
"zip:" and the connection is correctly made.

Is it the way to do it right, or is it just a workaround?
a+
Olivier

Le dimanche 25 décembre 2016 00:56:34 UTC-5, Olivier Milette a écrit :
>
> Hi everybody,
>
> I'm actually using h2database latest version 1.3.176 and I access my db 
> file that is included in my java project as resources files. When I run my 
> software from Eclipse, everything works fine, but when I run it from an 
> exported executable JAR where my db file is included I can't connect to the 
> DB file and I get an IOException.
>
> Here is the DB_URL that is built in my software using the getResource() 
> function:
>
>> jdbc:h2:jar:file:/C:/Users/Nemo/Google Drive/Partage/Mes 
>> Logiciels/Nutrion/Nutrion v0.3.jar!/ca/nutritix/nutrion/resources/FCEN2015"
>>
>
> I also tried to add these parameter to my DB_URL with no more success: 
>
>>     + ";FILE_LOCK=NO;MVCC=FALSE;MV_STORE=FALSE"
>>
>
> Here is the message from the exception that is thrown in my software when 
> run from the exported JAR, just at the moment when I try to connect the 
> database with the JDBC:
>
>> org.h2.jdbc.JdbcSQLException: IO Exception: "java.io.IOException: La syntaxe 
>> du nom de fichier, de répertoire ou de volume est incorrecte"; 
>>
>> "jar:file:/C:/Users/Nemo/Google Drive/Partage/Mes Logiciels/Nutrion/Nutrion 
>> v0.3.jar!/ca/nutritix/nutrion/resources/FCEN2015.mv.db" [90031-176]
>>
>>
> Here, I don't understand why the jdbc try to connect to a file with .mv.db 
> as extension. My file is .h2.db and is connected correctly when run from 
> Eclipse...
>
> Here is the portion of my code relative to the connection to the db and 
> first uses of it:
>
>> static final String JDBC_DRIVER = "org.h2.Driver";
>> static final String DB_URL = "jdbc:h2:" 
>> + 
>> MainApp.class.getResource("resources/FCEN2015.h2.db").getPath().replaceAll(".h2.db",
>>  
>> "").replaceAll("%20", " ");
>> static final String USER = "nutrion";
>> static final String PASS = "";
>>
> ...
>>
> Connection conn = null;
>>         Statement stmt = null;
>>         String sql = null;
>>         
>>         try{
>>             //Register JDBC driver
>>             Class.forName(JDBC_DRIVER);
>>     
>>             //Open a connection
>>             System.out.println("*** Connecting to database...");
>>             conn = DriverManager.getConnection(DB_URL,USER,PASS);
>>                       
>>             stmt = conn.createStatement();
>>             sql = "SELECT FOODID, FOODDESCRIPTIONF, SCIENTIFICNAME FROM 
>> FOOD_NAME";
>>             
>>             ResultSet rs = stmt.executeQuery(sql);
>>             while(rs.next()) {
>>
>  ...
>>
>
>  I wish I gave you enough pertinent and useful details for you to help me 
> with that.
> Sorry if I'm posting for a second time the same message, but I can't see 
> my first post of earlier today in the group...
>
> Thanks for that great and useful library that is h2database.
> A+
> Olivier
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to