What do I need to do to avoid an "out of memory" error when connecting jdbc to sqlite3 database?

What do I need to do to avoid an "out of memory" error when connecting jdbc to sqlite3 database?

java.sql.SQLException: out of memory at org.sqlite.DB.throwex(DB.java:288) at org.sqlite.NestedDB._open(NestedDB.java:73) at org.sqlite.DB.open(DB.java:77) at org.sqlite.Conn.<init>(Conn.java:88) at org.sqlite.JDBC.connect(JDBC.java:64) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at action.Actions.<init>(Actions.java:18) at controler.ClientControler.<init>(ClientControler.java:14) at main.Main.main(Main.java:20) Class.forName("org.sqlite.JDBC"); conn = DriverManager.getConnection("jdbc:sqlite:clients.db"); 
+6
source share
8 answers

This means that your clients.db file was not found. Try to find this file in a more appropriate way. Scroll to the "How to specify database files" section.

I downloaded the SQLite JAR, put it in my CLASSPATH, and found a tutorial here that worked great in less than five minutes. He put test.db at the root of my project, as expected.

I rewrote this tutorial the way I did it. It is working. Do not say that it does not bring anything.

 package sqlite; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; public class Test { private static final String DEFAULT_DRIVER = "org.sqlite.JDBC"; private static final String DEFAULT_URL = "jdbc:sqlite:data/test.db"; public static void main(String[] args) { Connection conn = null; try { conn = createConnection(DEFAULT_DRIVER, DEFAULT_URL); createTable(conn); List<Person> people = new ArrayList<Person>(); people.add(new Person("Gandhi", "politics")); people.add(new Person("Wittgenstein", "philosophy")); people.add(new Person("Turing", "computers")); saveAll(conn, people); List<Person> rows = findAll(conn); System.out.println(rows); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { close(conn); } } private static List<Person> findAll(Connection conn) throws SQLException { List<Person> rows = new ArrayList<Person>(); ResultSet rs = null; Statement stat = null; try { stat = conn.createStatement(); rs = stat.executeQuery("select * from people;"); while (rs.next()) { rows.add(new Person(rs.getString("name"), rs.getString("occupation"))); } } finally { close(stat); close(rs); } return rows; } private static void saveAll(Connection conn, List<Person> people) throws SQLException { PreparedStatement prep = null; try { prep = conn.prepareStatement("insert into people values (?, ?);"); for (Person person : people) { prep.setString(1, person.getName()); prep.setString(2, person.getOccupation()); prep.addBatch(); } conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(true); } finally { close(prep); } } private static void createTable(Connection conn) throws SQLException { Statement stat = null; try { stat = conn.createStatement(); stat.executeUpdate("drop table if exists people;"); stat.executeUpdate("create table people (name, occupation);"); } finally { close(stat); } } private static Connection createConnection(String driver, String url) throws ClassNotFoundException, SQLException { Class.forName(DEFAULT_DRIVER); Connection conn = DriverManager.getConnection(DEFAULT_URL); return conn; } private static void close(Connection conn) { try { if (conn != null) { conn.close(); } } catch (Exception e) { e.printStackTrace(); } } private static void close(Statement stat) { try { if (stat != null) { stat.close(); } } catch (Exception e) { e.printStackTrace(); } } private static void close(ResultSet rs) { try { if (rs != null) { rs.close(); } } catch (Exception e) { e.printStackTrace(); } } } class Person { private String name; private String occupation; Person(String name, String occupation) { this.name = name; this.occupation = occupation; } public String getName() { return this.name; } public String getOccupation() { return this.occupation; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{ name: ").append(this.name).append(", occupation: ").append(this.occupation).append(" }"); return sb.toString(); } } 
+5
source

I have the same problem and I think we ran into some error. The exception is absolutely not caused by a โ€œfile that does not existโ€: I carefully checked it with a proper test case.

The database itself is created using the sqlite3 official command line tool , so there is no corrupted database. I can confidently say that lib is broken somehow.

Please tell me what version of OS and JVM you have so that I can see if it matches mine, and we can prepare an error report.

+2
source

Yes, in case the file is not found, such a strange exception is generated "from memory". In the Eclipse IDE, instead of specifying the database name and path, separately specify the database file name in the field: Database location.

Example: Database location: c: \ temp \ test.db

+2
source

If the path to your database contains spaces, JDBC cannot find it. For example, C:/Program Files is incorrect. Must be C:/Program_Files . I had the same problem and now it works.

+1
source

I ran into this problem while trying to connect via Eclipse "Data Source Explorer".

On a Mac, when I double-clicked the file name in the view prompt, the folder and the database with the file name were put in the database. When I manually added the database file to the "Database Location" field, I was able to connect.

+1
source

As DarkCthulhu already mentioned, you should not have spaces in the path to the database file. This applies even if you have declared a relative path to it (for example, in your case). I am sure that the path to your project contains one or more spaces.

You can declare it with a complete space and spaces, or by changing the project location to a path without any spaces!

0
source

I ran into the same problem and I solved it. I used IntelliJ as my IDE. I will show you how I fixed the problem with screen shots, step by step. Hope this helps you.
1 - go to view | tool windows | database.
2 - now in the right hand a window is opened containing the name of your databases. Select the desired database, then press "alt + Enter",
Now, in the window that opens, make sure that you have correctly filled in the text fields! ( they should include the "fileName" directory. ). 13690578_894579790654050_4092612517568995120_n.jpg? Oh = 1ecedd2b5c1064f3f04b3a501b0802e7 & oe = 5832EF57

0
source

I had the same problem. My solution updates sqlite-jdbc dependency from version 3.7.2 to 3.16.1

0
source

Source: https://habr.com/ru/post/895035/


All Articles