At the moment I am writing a web application, one of the functions of which is to execute SQL queries on different databases (many bases, Oracle and MS SQL).
The databases are dynamically updated and I take them from the service, using remote parsing of the servers on which they spin and of which I am already composing.
I have to use the drivermanager
and class.forname
in this connection. Running class.forname
takes about 12 seconds and the driver is constantly re-registered.
I'm trying to figure out how to book class.forname
and continue to use the driver manager and register driver classes into it when starting tomkata8.
Datasors are not an option, there are too many bases, bases are changing.
Java8, tomcat8, jsp
- DriverManager.getDriver (String url)? If you have the necessary classes in the lib folder of the TS itself, then you can get them as well - Chubatiy
- Yes, String = "oracle.jdbc.driver.oracleDriver"; in libom tomkata 2 drivers for 2 OS, but with get driver - no suitable driver .. - Igor Bogatyrchuk
- Not. String is just a url. Well, for example, for oracle DriverManager.getDriver ("jdbc: oracle: thin:") - Chubatiy
- Thank! It worked! :)) - Igor Bogatyrchuk
- am making out then as the answer - Chubatiy
|
1 answer
- You need to throw all the drivers in the
lib
folder intomcat
- In the code to get the driver, call
DriverManager.getDriver(String url)
, whereurl
is the beginning of the database connectionurl
As an example for oracle :
DriverManager.getDriver("jdbc:oracle:thin:")
To view all available drivers:
Enumeration<Driver> e = DriverManager.getDrivers(); while (e.hasMoreElements()) { Object driverAsObject = e.nextElement(); System.out.println("JDBC Driver=" + driverAsObject); }
|