How to fix tzdb.dat not found error in java?
Sophia Terry
When I try to connect my gradle project with sqlite database, I have an error:
Exception in thread "main" java.lang.Error: java.io.FileNotFoundException: null\lib\tzdb.dat (The system cannot find the path specified) at sun.util.calendar.ZoneInfoFile$1.run(ZoneInfoFile.java:261) at java.security.AccessController.doPrivileged(Native Method) at sun.util.calendar.ZoneInfoFile.<clinit>(ZoneInfoFile.java:251) at sun.util.calendar.ZoneInfo.getTimeZone(ZoneInfo.java:589) at java.util.TimeZone.getTimeZone(TimeZone.java:560) at java.util.TimeZone.setDefaultZone(TimeZone.java:666) at java.util.TimeZone.getDefaultRef(TimeZone.java:636) at java.util.TimeZone.getDefault(TimeZone.java:625) at org.sqlite.date.FormatCache.getInstance(FormatCache.java:74) at org.sqlite.date.FastDateFormat.getInstance(FastDateFormat.java:129) at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:70) at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:25) at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:24) at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45) at org.sqlite.JDBC.createConnection(JDBC.java:114) at org.sqlite.JDBC.connect(JDBC.java:88) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:270) at repository.JdbcUtils.getNewConnection(JdbcUtils.java:39) at repository.JdbcUtils.getConnection(JdbcUtils.java:52) at repository.RepositoryLog.findOne(RepositoryLog.java:28) at Main.main(Main.java:28) Caused by: java.io.FileNotFoundException: null\lib\tzdb.dat (The system cannot find the path specified) at java.io.FileInputStream.open0(Native Method) at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.<init>(FileInputStream.java:138) at sun.util.calendar.ZoneInfoFile$1.run(ZoneInfoFile.java:255) ... 21 moreI've tried to debug it but it says that it is a timezone problem and I don't know why this issue appears. I thought that this could be a a problem because of Java10, so I also installed Java1.8 but it didn't work.
private Connection getNewConnection() { //I use the driver and the url from a bd.config file and it is saved in my //variables corectly String driver= jdbcProps.getProperty("jdbc.driver"); String url=jdbcProps.getProperty("jdbc.url"); String user=jdbcProps.getProperty("jdbc.user"); String pass=jdbcProps.getProperty("jdbc.pass"); Connection con=null; try{ Class.forName(driver); //this is where my error appears con= DriverManager.getConnection(url); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { System.out.println("Error getting connection "+e); //e.printStackTrace(); } return con; }I expect only to connect to my database and work with the database corectly
12 Answers
I Just had this problem and could only find this Question when I Googled it.
I eventually fixed it by following a hint on an Mboard ([email protected])
They mentioned doing:System.setProperties(null); somewhere, This has the effect of deleting all System variables.
When using a Properties p = new Properties(); You have a blank set of System variables. Therefore doing System.setProperties(p); has the same effect as above.
If you want to add a new variable then you should first get the Properties with
Properties p = System.getProperties();
Then add your new ones:
p.setProperty("MyProperty", "MyValue");
and then write it back with the set method.
I hope this helps someone in the Future.
1Go to your C:\Program Files\Java\jre1.8.0_202\lib directory search for tzdb.dat file and copy it from here and paste in C:\Program Files\Java\jdk-13\lib directory hope it will work