[英]Can I use jdbc without jar drivers?
Profesor in my University send us the task related to graphs where he says : 我大学的教授向我们发送了与图有关的任务,他说:
data for the task are stored in database. 任务的数据存储在数据库中。 Connection to this database is made by line of codes:
通过以下代码行可以连接到该数据库:
String database = <connection_string>; //
Connection conn = DriverManager.getConnection(database);
where 哪里
<connection_string> is command line param.
Nobody knows which of database he is going to use in his environment and another important thing is that running program should be released only with two files 没有人知道他将在自己的环境中使用哪个数据库,另一个重要的事情是正在运行的程序应该仅由两个文件发布
path.java
main.java
program have to run after this line in comand line: 程序必须在comand行的这一行之后运行:
java Main <connection_string>
My question is: How to implement such funcitonality without knowledge about kind of database ? 我的问题是:如何在不了解数据库种类的情况下实现这种功能? Is it possible to run connection to database without any jdbc external jar ?
是否可以在没有任何jdbc外部jar的情况下运行与数据库的连接?
Thanks for help 感谢帮助
Ok, so in your main method, args[1]
is the JDBC connection String. 好的,因此在您的主要方法中,
args[1]
是JDBC连接字符串。 You can use some splitting and/or regexes to comparate that with a list of connection strings/driver equivalences like this one to guess the fully qualified driver class name, and then do Class.forName(driver);
你可以使用一些分裂和/或正则表达式来comparate与连接字符串列表/像司机等价这一猜测完全合格的驱动程序类名,然后做
Class.forName(driver);
. 。 After that, you can get connections from the driver.
之后,您可以从驱动程序获得连接。
The profesor still has to add the driver to the classpath on his end, but your code will work whatever he uses. 教授仍然必须在其末尾将驱动程序添加到类路径中,但是无论他使用什么代码都可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.