How can use relative paths in database connection? | SoloLearn: Learn to code for FREE!

0

How can use relative paths in database connection?

public class ConnectionManager { File file = new File("Data/Uni.accdb"); private static String dbPath = file.getAbsolutePath(); private static String url = "jdbc:ucanaccess:// '"+dbPath+"' "; //I have an error here private static String driverName = "net.ucanaccess.jdbc.UcanaccessDriver"; private static Connection connection; private static String urlstring; public static Connection getConnection() { try { Class.forName(driverName); try { connection = DriverManager.getConnection(url); } catch (SQLException ex) { System.out.println("Failed to create the database connection."); } } catch (ClassNotFoundException ex) { System.out.println("Driver not found."); } return connection; } } // if remove static, can not get getConnection in other classes.

7/24/2017 3:16:17 PM

hamid

4 Answers

New Answer

+1

java?

0

yes, in java

0

i know its totally irrelevant to this topic...but what do you think about QB64?

0

I use relative path (dbPath) In this code, so its not irrelevant to topic. and I have an error in: private static String url= "jdbc:ucanaccess:// '"+dbPath+"' "; if I remove static from that, so can not get method (getConnection) from this class(ConnectionManager ) in other classes.