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.

24th Jul 2017, 3:16 PM
hamid
hamid - avatar
4 Respostas
+ 1
java?
24th Jul 2017, 3:17 PM
RISH#
RISH# - avatar
0
yes, in java
24th Jul 2017, 3:28 PM
hamid
hamid - avatar
0
i know its totally irrelevant to this topic...but what do you think about QB64?
24th Jul 2017, 3:35 PM
RISH#
RISH# - avatar
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.
24th Jul 2017, 3:49 PM
hamid
hamid - avatar