简体   繁体   English

我可以在没有jar驱动程序的情况下使用jdbc吗?

[英]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.

相关问题 如何找到所有可用的 JDBC 驱动程序? - How can I find all JDBC drivers available? 如何在连接时避免在Eclipse中使用多个JDBC驱动程序进行JAR碰撞? - How do I avoid JAR Collision with multiple JDBC drivers in Eclipse on connect? 如何在同一个应用程序中使用多个JDBC驱动程序? - How to use multiple JDBC drivers in the same application? JDBC - java 看不到已安装的驱动程序 - JDBC - java can't see installed drivers 我可以在没有Commons-logging.jar的情况下使用Apache HTTPClient - Can I use Apache HTTPClient without Commons-logging.jar 如何防止Tomcat6在WEB-INF / lib中预加载JDBC驱动程序? - How can I prevent Tomcat6 from pre-loading JDBC Drivers in WEB-INF/lib? 使用Jar文件和命令提示符时,jdbc出现问题 - problem with jdbc when I use Jar file and command prompt 我可以在Docker镜像中捆绑Oracle JDBC驱动程序JAR吗? - Can I bundle the Oracle JDBC driver JAR in a Docker image? 如何在我的 Java 项目中包含 PostgreSQL JDBC JAR? - How can I include the PostgreSQL JDBC JAR in my Java project? 如何在不使用Apache DDLUtils的情况下使用JDBC将模式从一个数据库复制到另一个数据库? - How can I use JDBC to copy schema from one database to another without using Apache DDLUtils?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM