JDBC FAQ-from Sun Forum

Source: Internet
Author: User
Tags garbage collection connect odbc sql new features string versions access
Problem
JDBC FAQ


Directory

What is the JDBC 3.0 API?

Does JDBC-ODBC bridge support the new features in the JDBC 3.0 API?

Can JDBC-ODBC bridge be used with applets?

How do I start debugging issues related to the JDBC API?

How can I use the JDBC API to access a desktop database like Microsoft access over the network?

What are the available drivers that support JDBC technology?

What are the available JDBC API documentation?

Is there an ODBC driver that cannot work with JDBC-ODBC Bridge?

What causes "no suitable driver" (no suitable driver) error?

Why can't I find the Java.sql.DriverManager class?

How do I retrieve an entire row of data at one time instead of calling the Resultset.getxxx method once for each column?

Why does the ODBC driver manager return "data source name not found and no default driver specified vendor:0" (DataSource name not found and no default driver specified vendor: 0)?

Do all required JDBC drivers create a connection to the database portion of the JDK?

Is the Jdbc-odbc bridge a multi-threaded one?

Does JDBC-ODBC bridge support multiple concurrent open statements in each connection?

Why can't I call the ResultSet method Afterlast and Beforefirst when the next method works?

How can I retrieve a String or other object type without creating a new object at a time?

There is a method getColumnCount in the JDBC API. Is there a similar way to find the number of rows in the result set?

I want to download the Java 2 SDK, Standard Edition (previous JDK 1.2) Jdbc-odbc Bridge. I'm a beginner of the JDBC API and I want to start with bridge. What am I supposed to do?

If I use the JDBC API, is it necessary for me to use ODBC Control (ODBC underneath)?

Once you have the Sun's Java 2 SDK, Standard Edition, what else do you need to do to connect to the database?








1. What is the JDBC 3.0 API?



The JDBC 3.0 API is the last update of the JDBC API. It contains a number of features, including scrollable result sets and sql:1999 data types.


Back to the top of the page


2. Does JDBC-ODBC bridge support the new features in the JDBC 3.0 API?



JDBC-ODBC Bridge provides a limited subset of the JDBC 3.0 API.


Back to the top of the page


3. Can JDBC-ODBC bridge be used with applets?



Untrusted applets running in browsers, such as Netscape Navigator, do not allow JDBC-ODBC bridge to be used. JDBC-ODBC Bridge does not allow untrusted code to invoke it for security reasons. This is a good aspect because it indicates that untrusted applets downloaded by the browser do not bypass Java security by invoking ODBC. Remember that ODBC is native code, so once you call the Odbc,java programming language, there is no guarantee that security conflicts will not occur. On the other hand, the Pure Java JDBC driver works well with the applet. They are fully downloadable and do not require any client configuration.



Finally, I would like to mention that Jdbc-odbc Bridge can be used with applets because the applet browser assumes that the applet is trusted, so the applet runs in the applet browser. It is often dangerous to turn off applet security, but it may be appropriate in some controlled settings, such as for applets that are used only in secure Intranet environments. Remember that if you choose this option, you will encounter a warning and use the full Java (All-java) JDBC driver as soon as possible to avoid security problems.


Back to the top of the page


4. How do I start debugging issues related to the JDBC API?



A good way to find out what the JDBC call is doing is to enable JDBC tracing. The JDBC trace contains a detailed list of activities that occur in the system associated with the JDBC operation.



If you use the DriverManager tool to create a database connection, use the Drivermanager.setlogwriter method to enable tracing for the JDBC operation. If you use the DataSource object to get the connection, use the Datasource.setlogwriter method to enable tracing. (For a centralized connection, you use the Connectionpooldatasource.setlogwriter method; The Xadatasource.setlogwriter method is used for connections that participate in distributed transactions.) )


Back to the top of the page


5. How can I use the JDBC API to access a desktop database like Microsoft access over the network?



Most desktop databases currently require the use of ODBC-dictated JDBC solutions. This is because the vendors of these database products have not yet implemented the full Java JDBC driver.



The best approach is to use a commercial JDBC driver that supports ODBC and databases that you want to use. See the JDBC Driver page for a list of available JDBC drivers.



Jdbc-odbc Bridge from Sun Java Software does not provide a separate access to the desktop database. JDBC-ODBC Bridge loads ODBC as a local DLL, and typical ODBC drives for desktop databases, such as Access, are not on the network. However, Jdbc-odbc Bridge can be used with RMI-JDBC bridge to access databases such as access over the network. This RMI-JDBC-ODBC solution is free of charge.


Back to the top of the page


6. What are the available drivers that support JDBC technology?



Refer to the Web page that supports the JDBC technology driver to get a list of currently available drivers.


Back to the top of the page


7. What are the available JDBC API documentation?



See the JDBC Technology home page, which has links to information about JDBC technology. This page links to information about features and benefits, a series of new features, a section on getting Started, an online tutorial and a section on driver requirements, and it links to spec and Javadoc documentation.


Back to the top of the page


8. Is there an ODBC driver that cannot work with JDBC-ODBC Bridge?



Most ODBC 2.0 drivers should work with bridge. Because there are some differences in functionality between ODBC drivers, bridge functionality can be affected. Bridge works with a popular PC database, such as Microsoft Access and FoxPro.


Back to the top of the page


9. What causes "no suitable driver" (no suitable driver) error?



A "No suitable driver" error often occurs during the call to the Drivermanager.getconnection method. The reason may be that the appropriate JDBC driver fails to load before the Getconnection method is invoked, or it may be specifying an illegal JDBC url--a URL that is not recognized by the JDBC driver. The best way to do this is to check the documentation for the JDBC driver or contact your JDBC driver vendor if you suspect you are specifying a URL that is not recognized by the JDBC driver.



Also, when you are using JDBC-ODBC Bridge, this error can occur if you cannot load one or more shared libraries required by bridge. If you think this is the reason, check your configuration to make sure Bridge has access to the shared library.


Back to the top of the page


10. Why can't I find the Java.sql.DriverManager class?



This problem may be caused by running the JDBC applet in a browser that supports JDK 1.0.2 (such as Netscape Navigator 3.0). The JDK 1.0.2 does not contain the JDBC API, so Java virtual machines running in browsers usually cannot find DriverManager classes.



Here is a solution that does not require any additional configuration on the Web client. Remember that for security reasons, the classes in the Java.* package cannot be downloaded by most browsers. As a result, many of the full Java driver vendors provide different versions of the java.sql.* classes and name them jdbc.sql.*, together with a driver version that uses these modified classes. If you import jdbc.sql.* instead of java.sql.* in the applet code and add the Jdbc.sql.* class provided by the JDBC driver provider in the applet's codebase (codebase), all JD required by the applet The BC class can be downloaded at run time by the browser, including the DriverManager class.



This solution will enable applets to work in any client browsers that support JDK 1.0.2. Applets can also work in browsers that support JDK 1.1, but for performance reasons, you may want to switch to JDK 1.1 classes. Also keep in mind that the solution depicted here is just one example, and other solutions are possible.


Back to the top of the page


11. How do I retrieve an entire row of data at one time instead of calling the Resultset.getxxx method once for each column?



The Resultset.getxxx method is the only way to retrieve data from a ResultSet object, indicating that a call must be made to each column in the row. This is unlikely to be the cause of performance problems, however, because it is hard to see how to extract a column in any situation without having to spend at least one function call at a time. We welcome the information that developers provide about this topic.


Back to the top of the page


12. Why the ODBC driver Manager will return "data source name not found and no default driver specified vendor:0" (data source name is not found and no default driver specified vendor: 0) ?



This type of error can occur during an attempt to connect to a database using bridge. First, note that the error is from the ODBC driver Manager. This indicates that bridge--is a normal ODBC client--the ODBC has been successfully invoked, so the problem is not due to the fact that the local library does not exist. In this case, it indicates that the error is caused by the fact that the ODBC DSN (data source name) needs to be configured on the client computer. Developers often forget to do this, thinking that bridge should find the DSN configured on the remote server computer.


Back to the top of the page


13. Do all required JDBC drivers create a connection to the database portion of the JDK?



No. In addition to Jdbc-odbc Bridge, no driver that supports JDBC technology is bundled with JDK 1.1.x or Java 2 Platform versions. As a result, developers need to get the driver and install it before they can connect to the database. We are considering bundling a driver that supports JDBC technology in the future.


Back to the top of the page


Is Jdbc-odbc bridge a multi-threaded one?



No. JDBC-ODBC Bridge does not support concurrent access from different threads. JDBC-ODBC Bridge uses the synchronization method to serialize all its calls to ODBC. Multithreaded Java programs can use bridge, but they do not have the advantage of multithreading. In addition, deadlocks can occur between a database-held lock and a signal used by bridge (semaphore). We are considering deleting the synchronization method in the future. The purpose of adding them was to make things easier for people who write Java programs that use a single threaded ODBC driver.


Back to the top of the page


JDBC-ODBC Bridge Do you support multiple concurrent open statements in each connection?



No. When using Jdbc-odbc Bridge, only one Statement object can be opened for each connection.


Back to the top of the page


16. When the next method works, why can't I call the ResultSet method Afterlast and Beforefirst?



You may be using a driver that is implemented for the JDBC 1.0 API. You need to upgrade to the JDBC 2.0 driver, which implements a scrollable result set. It also guarantees that the code has created scrollable result sets and that the DBMS being used supports them.


Back to the top of the page


17. How can I retrieve a String or other object type without creating a new object at a time?



Unnecessarily creating potentially large numbers of objects (millions of) and disposing of them in a garbage collection can really affect performance. The following approach might be better: use the JDBC API instead of always allocating new objects to retrieve data such as strings.



We are working on this topic to determine if the JDBC API should be improved in some places. This information may be available in the future. Also, if you have any comments on this issue, please send it to us as well.


Back to the top of the page


18. There is a method getColumnCount in the JDBC API. Is there a similar way to find the number of rows in the result set?



No, but it's easy to find the number of rows. If you are using the scrollable result set RS, you can call Rs.last, and then call Rs.getrow to find the number of rows in Rs. If the result set is not scrollable, you can also calculate the number of rows by iterating through the result set, or by submitting a query that adds the Count column to the SELECT clause to get the number of rows.


Back to the top of the page


19. I would like to download the Java 2 SDK, Standard Edition (formerly JDK 1.2) JDBC-ODBC Bridge. I'm a beginner of the JDBC API and I want to start with bridge. What am I supposed to do?



Jdbc-odbc Bridge is bundled with the Java 2 SDK, Standard Edition, so there is no need to download it separately.


Back to the top of the page


20. If I use the JDBC API, is it necessary for me to use ODBC Dominance (ODBC underneath)?



It's not necessary, it's just one of many possible solutions. We recommend using pure Java JDBC-enabled drivers (Type 3 or 4) to get all the benefits of the Java programming language and the JDBC API.


Back to the top of the page


21. Once you have the Sun's Java 2 SDK, Standard Edition, what else do you need to do to connect to the database?



You still need to obtain and install a driver that supports JDBC technology, and it supports the database you are using. There are many drivers from a variety of resources. You can also try to use JDBC-ODBC Bridge, provided that you have created an ODBC database connection. Bridge is provided with the Java 2 SDK, Standard Edition, which itself does not require any additional installation. Bridge is an ordinary ODBC client. Note, however, that you should use JDBC-ODBC Bridge only for pilot prototypes or for other drivers that are not available to use.


Back to the top of the page







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.