Java how to reference a downloaded driver
DriverManager class. This class provides a basic service for managing a set of JDBC drivers. The registerDriver method takes as input a "driver" class, that is, a class that implements the java. Driver interface, as is the case with OracleDriver. Note: Alternatively, you can use the forName method of the java. Class class to load the JDBC drivers directly.
For example: Class. OracleDriver" ;. However, this method is valid only for JDK-compliant Java virtual machines. It is not valid for Microsoft Java virtual machines. Once you have registered the driver, you can open a connection to the database with the static getConnection method of the java. The type of the object returned is java.
The following example connects user scott with password tiger to a database with SID orcl through port of host myhost , using the Thin driver. The following example connects user scott with password tiger to a database on host myhost using the OCI driver. In this case, however, the URL includes the userid and password, and is the only input parameter. If you want to connect with the Thin driver, you must specify the port number and SID.
The following signature takes a URL, together with a properties object that specifies user name and password perhaps among other things :. For example:. Properties ; info. Skip navigation links. Object oracle. OracleDriver oracle. Driver interface. Register the JDBC drivers To access a database from a Java application, you must first provide the code to register your installed driver with your program.
You register the driver only once in your Java application. OracleDriver ; Open a Connection to a database Once you have registered the driver, you can open a connection to the database with the static getConnection method of the java. For example: java. Set this to "false" if you want to avoid many calls to Statement. This is espcially usefull for PreparedStatement where a call to setEscapeProcessing false would have no effect. Collectives on Stack Overflow. Learn more. Asked 8 years, 5 months ago.
Active 5 years, 11 months ago. Viewed 24k times. I've used this command but I got an error: java -jar mongo-java-driver Improve this question. TangoStar TangoStar 2 2 gold badges 8 8 silver badges 22 22 bronze badges. Add a comment. Active Oldest Votes. First, that is not the correct jar. The jar you are referencing above contains the javadocs. The driver jar is: mongo-java-driver Improve this answer. TangoStar - You can't run these jars like you are trying to above. The are not executable.
You have to add them to your classpath and use them in your code. Did you read the link I supplied? I have also edited my answer for clarity. Thufir - The drivers are provided on the Mongo site: docs.
I assume they are not included with the download because there are so many. You can go to the driver site above and get the driver that matches your version of mongodb. If you want to use MongoDB by itself, you can use it with the Mongo shell. John Feibusch John Feibusch 63 2 2 bronze badges. Or Download the single file.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Who owns this outage?
0コメント