Java 爪哇及;访问动态路由
我有一个java access数据库的连接,代码如下:Java 爪哇及;访问动态路由,java,Java,我有一个java access数据库的连接,代码如下: package class; import java.sql.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; public class Conexion { Connection cn = null; Statement st = null;
package class;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class Conexion {
Connection cn = null;
Statement st = null;
public Conexion(){
try {
String routefile = "C:\\testbd\\BD.accdb";
String url = "jdbc:ucanaccess://" + routefile;
cn = DriverManager.getConnection(url);
st = cn.createStatement();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Could not connect to the database: " + e);
System.err.println("Failed to connect to database: " + e);
}
}
public Connection getConnection(){
return cn;
}
public void Desconexion(){
try {
cn.close();
} catch (SQLException e) {
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, e);
System.err.println("Failed to close the database: "+ e);
JOptionPane.showMessageDialog(null, "Failed to close the connection to the database.");
}
}
}
我需要实现的是一个在任何计算机上都适用的通用路径,我想知道是否有任何方法可以帮助我做到这一点,应用程序可以在任何目录下的任何其他计算机上运行,我想在.accdb数据库与.jar位于同一目录下的唯一条件下实现与数据库数据的连接,我如何实现这一点
我已经修改了路线:
String routefile=“C:\\testbd\\BD.accdb”代码>
String url=“jdbc:ucanaccess://”+routefile代码>
没有实现我现在想要的
我想通过这个视频实现如下示例:
File File=new文件(“src/media/video.mp4”)代码>
在这种情况下,只要src文件夹位于可以执行视频的.jar旁边,我就希望在数据库中实现同样的效果
提前非常感谢您,感谢您能给我的任何帮助