简体   繁体   English

从Java同时使用MySQL 3.x和5.x.

[英]Using MySQL 3.x and 5.x simultaneously from Java

How can I use MySQL 3.x and MySQL 5.x simultaneously from my Java application if the two versions need different versions of JDBC drivers but the driver class name is the same? 如果两个版本需要不同版本的JDBC驱动程序但驱动程序类名相同,我如何同时从我的Java应用程序中使用MySQL 3.x和MySQL 5.x?

For MySQL 3.x I downloaded MySQL Connector/J 3.0.17 and for MySQL 5.x I have MySQL Connector/J 5.1.12. 对于MySQL 3.x,我下载了MySQL Connector / J 3.0.17,对于MySQL 5.x,我有MySQL Connector / J 5.1.12。 How can I use them both? 我怎么能同时使用它们?

First check whether (as mentioned by @DaveHowes +1) you can use JDBC driver for v5 with DB v3. 首先检查(如@DaveHowes +1所述)您是否可以将JDBC驱动程序用于带有DB v3的v5。 It probably works. 它可能有效。 In this case you have no problem. 在这种情况下,你没有问题。

If it does not work you have to use separate class loaders for 2 connectors to 2 different DBs. 如果它不起作用,则必须使用单独的类加载器,用于2个连接器到2个不同的DB。 So, neither v5 nor v3 JDBC driver will not be in "regular" classpath of your application. 因此,v5和v3 JDBC驱动程序都不会处于应用程序的“常规”类路径中。 Instead you should create some kind of wrapper that will instantiate its own UrlClassLoader : and start driver. 相反,你应该创建一些将实例化自己的UrlClassLoader的包装器:并启动驱动程序。 The mentioned collector should expose API that allows you to perform JDBC query. 提到的收集器应该公开允许您执行JDBC查询的API。 I hope this will work. 我希望这会奏效。 All this if you are using pure JDBC. 如果您使用纯JDBC,那么所有这些。 If you are using some kind of tools (eg Hibernate, iBatis etc.) I wish you good luck :) and suggest to ask more specific question that mentions tool you are using. 如果您正在使用某种工具(例如Hibernate,iBatis等),我祝您好运:)并建议您提出更具体的问题,提及您正在使用的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM