{"action":"created","issue":{"url":"https://api.github.com/repos/xerial/sqlite-jdbc/issues/139","repository_url":"https://api.github.com/repos/xerial/sqlite-jdbc","labels_url":"https://api.github.com/repos/xerial/sqlite-jdbc/issues/139/labels{/name}","comments_url":"https://api.github.com/repos/xerial/sqlite-jdbc/issues/139/comments","events_url":"https://api.github.com/repos/xerial/sqlite-jdbc/issues/139/events","html_url":"https://github.com/xerial/sqlite-jdbc/issues/139","id":166716499,"number":139,"title":"Unable to acquire a JDBC connection with a local temp file","user":{"login":"krishnanand","id":1548607,"avatar_url":"https://avatars.githubusercontent.com/u/1548607?v=3","gravatar_id":"","url":"https://api.github.com/users/krishnanand","html_url":"https://github.com/krishnanand","followers_url":"https://api.github.com/users/krishnanand/followers","following_url":"https://api.github.com/users/krishnanand/following{/other_user}","gists_url":"https://api.github.com/users/krishnanand/gists{/gist_id}","starred_url":"https://api.github.com/users/krishnanand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krishnanand/subscriptions","organizations_url":"https://api.github.com/users/krishnanand/orgs","repos_url":"https://api.github.com/users/krishnanand/repos","events_url":"https://api.github.com/users/krishnanand/events{/privacy}","received_events_url":"https://api.github.com/users/krishnanand/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-21T01:11:07Z","updated_at":"2016-07-22T13:57:49Z","closed_at":null,"body":"I apologize if this has been addressed before. I could not find any resolution to my problem in spite of [asking on StackOverflow](http://stackoverflow.com/questions/38409036/unable-to-connect-to-sqlite-file-on-disk).\r\n\r\nI am hoping that someone can help. My usecase is given below:\r\n\r\n1. I upload the SQLite local db file to a web app. This is automatically converted into a multipart file from which I need to extract the content.\r\n2. Because this is a multipart file, I have access to the byte array, which is passed to the function.\r\n3. Write the byte array to a local temp file.\r\n4. Create a connection to make JDBC calls.\r\n\r\nMy stack trace on a Windows machine:\r\n\r\n```\r\ncom.mycompany.cms.tools.dao.ContentRetrievalException: Unable to retrieve content for Unable to parse file : cms4275726046178009363.db\r\n\tat com.mycompany.cms.tools.service.CmsContentServiceImpl.readContentFromSqliteStream(CmsContentServiceImpl.java:156)\r\n\tat com.mycompany.cms.tools.service.CmsContentServiceImplTest.testReadContentFromSqliteStream(CmsContentServiceImplTest.java:75)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:498)\r\n\tat org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)\r\n\tat org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:197)\r\n\tat org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:175)\r\n\tat org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:209)\r\n\tat org.testng.internal.Invoker.invokeMethod(Invoker.java:639)\r\n\tat org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)\r\n\tat org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)\r\n\tat org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)\r\n\tat org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)\r\n\tat org.testng.TestRunner.privateRun(TestRunner.java:782)\r\n\tat org.testng.TestRunner.run(TestRunner.java:632)\r\n\tat org.testng.SuiteRunner.runTest(SuiteRunner.java:366)\r\n\tat org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)\r\n\tat org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)\r\n\tat org.testng.SuiteRunner.run(SuiteRunner.java:268)\r\n\tat org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)\r\n\tat org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)\r\n\tat org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)\r\n\tat org.testng.TestNG.runSuitesLocally(TestNG.java:1169)\r\n\tat org.testng.TestNG.run(TestNG.java:1064)\r\n\tat org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)\r\n\tat org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)\r\n\tat org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)\r\nCaused by: java.sql.SQLException: No suitable driver found for jdbc:sqlite:C:\\Users\\zk5426x\\AppData\\Local\\Temp\\cms4275726046178009363.db\r\n\tat java.sql.DriverManager.getConnection(DriverManager.java:689)\r\n\tat java.sql.DriverManager.getConnection(DriverManager.java:270)\r\n\tat com.mycompany.cms.tools.dao.CmsLocalContentDao.readContentsFromResource(CmsLocalContentDao.java:45)\r\n\t... 30 more\r\n```\r\n\r\nMy code snippet:\r\n\r\n```\r\npublic Set<CmsXServiceContent> readContentFromSqliteStream(byte[] bytes) throws Exception {\r\n       Path path = null;\r\n    try {\r\n      path = Files.createTempFile(\"cms\", \".db\");\r\n      path.toFile().setWritable(true);\r\n      path.getParentFile().setWritable(true);\r\n      if (LOGGER.isInfoEnabled()) {\r\n        LOGGER.info(\"Temporary file created = \" + path.toString());\r\n      }\r\n      try (ByteArrayInputStream is = new ByteArrayInputStream(bytes);) {\r\n        Files.copy(is, path, StandardCopyOption.REPLACE_EXISTING);\r\n        Class.forName(\"org.sqlite.JDBC\");\r\n     // This following statement throws an exception.\r\n      try(\r\n        Connection conn =\r\n            DriverManager.getConnection(\r\n                 \"jdbc:sqlite:\" +  path.toFile().getCanonicalPath());) {\r\n\r\n        // Prepared Statements and result set query to return the appropriate output.\r\n        }\r\n      }\r\n    } catch (Exception e) {\r\n      LOGGER.error(\"Unable to create a temporary file: cms.db\");\r\n      throw e;\r\n    } finally {\r\n      if (path != null) {\r\n        path.toFile().deleteOnExit();\r\n      }\r\n    }\r\n}\r\n```\r\nMy Maven configuration\r\n```\r\n<dependency>\r\n\t<groupId>org.xerial</groupId>\r\n\t<artifactId>sqlite-jdbc</artifactId>\r\n\t<version>3.8.7</version>\r\n</dependency>\r\n```\r\nThe output of the following statements are as follows\r\n\r\n```\r\nSystem.out.println(localFile.getPath());\r\nSystem.out.println(localFile.getCanonicalPath());\r\nSystem.out.println(localFile.getAbsolutePath());\r\nSystem.out.println(localFile.getName());\r\n```\r\n\r\nis \r\n\r\n```\r\nC:\\Users\\zk5426x\\AppData\\Local\\Temp\\cms7629729726748856652.db\r\nC:\\Users\\zk5426x\\AppData\\Local\\Temp\\cms7629729726748856652.db\r\nC:\\Users\\zk5426x\\AppData\\Local\\Temp\\cms7629729726748856652.db\r\ncms7629729726748856652.db\r\n```\r\n\r\n\r\nI don't know what I am doing wrong. Any assistance would be appreciated. "},"comment":{"url":"https://api.github.com/repos/xerial/sqlite-jdbc/issues/comments/234550816","html_url":"https://github.com/xerial/sqlite-jdbc/issues/139#issuecomment-234550816","issue_url":"https://api.github.com/repos/xerial/sqlite-jdbc/issues/139","id":234550816,"user":{"login":"gitblit","id":868217,"avatar_url":"https://avatars.githubusercontent.com/u/868217?v=3","gravatar_id":"","url":"https://api.github.com/users/gitblit","html_url":"https://github.com/gitblit","followers_url":"https://api.github.com/users/gitblit/followers","following_url":"https://api.github.com/users/gitblit/following{/other_user}","gists_url":"https://api.github.com/users/gitblit/gists{/gist_id}","starred_url":"https://api.github.com/users/gitblit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gitblit/subscriptions","organizations_url":"https://api.github.com/users/gitblit/orgs","repos_url":"https://api.github.com/users/gitblit/repos","events_url":"https://api.github.com/users/gitblit/events{/privacy}","received_events_url":"https://api.github.com/users/gitblit/received_events","type":"User","site_admin":false},"created_at":"2016-07-22T13:57:49Z","updated_at":"2016-07-22T13:57:49Z","body":"Your approach looks fine but I can't help feeling that the shared\nstacktrace is incomplete. I would expect to see an IOException or\nSQLException. Or at least some explanation.\n"}}
{"actor":{"display_login":"gitblit"}}