title: How to get realative path for database?
body: <p>I am developing a jframe to store some data in database by using textfields and all. i have following code for database connection. I am using sqlite database.</p>
  
  <pre><code>**Connectdatabase.java**
  
      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      package shreesai;
  
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.SQLException;
      import javax.swing.JOptionPane;
  
      /**
       *
       * @author DeepRocks
       */
      public class Connectdatabase {
  
          Connection con = null;
  
          public static Connection ConnecrDb(){
  
              try{
                  Class.forName("org.sqlite.JDBC");
                  Connection con = DriverManager.getConnection("jdbc:sqlite:G:\\Development\\Project\\database\\shreesai.sqlite");
                  return con;
              }
              catch(ClassNotFoundException | SQLException e){
                  JOptionPane.showMessageDialog(null,"Problem with connection of database");
                  return null;
              }
          }
  }****
  </code></pre>
  
  <p><strong>/* ALL IS WORKING FINE WITH THIS BUT I WANT THAT IS IF I EXPORT THIS PROJECT TO JAR AND MY CLIENT WILL RUN JAR FROM DIFFERENT PATH THEN????*/</strong></p>
  
  <p>I've tried using this code </p>
  
  <pre><code>public class Connectdatabase {
  
      Connection con = null;
  
      public static Connection ConnecrDb(){
  
          try{
              String dir = System.getProperty("user.dir");
              Class.forName("org.sqlite.JDBC");
              Connection con = DriverManager.getConnection("jdbc:sqlite:"+dir+"shreesai.sqlite");
              return con;
          }
          catch(ClassNotFoundException | SQLException e){
              JOptionPane.showMessageDialog(null,"Problem with connection of database");
              return null;
          }
      }
  
  }
  </code></pre>
  
  <p>Even i tried this one :</p>
  
  <pre><code>public class Connectdatabase {
  
          Connection con = null;
  
          public static Connection ConnecrDb(){
  
              try{
                  String dir = System.getProperty("user.dir");
                  String maindir = dir + File.separator + File.separator ;
                  Class.forName("org.sqlite.JDBC");
                  Connection con = DriverManager.getConnection("jdbc:sqlite:"+maindir+"shreesai.sqlite");
                  return con;
              }
              catch(ClassNotFoundException | SQLException e){
                  JOptionPane.showMessageDialog(null,"Problem with connection of database");
                  return null;
              }
          }
  
      }
  </code></pre>
  
  <p>But <strong>NOTHING</strong> i think there must be problem with that double backslashes cause dir returning : <strong>G:\Development\Project\database</strong>. and we want G:\\Development\\Project\\database\\</p>
  
  <p>Any help?</p>