Java-based Oracle database self-built tool Library

Source: Internet
Author: User

Java-based Oracle database self-built tool Library

When I learned how to operate Oracle databases in Java, I suddenly thought that I could create a tool class like php, which could greatly reduce the complexity of the Code. It can also improve work efficiency.

If java cannot build a tool class by itself, it is very ridiculous. However, some problems have occurred during the creation process and it is hoped that similar errors will not be made in the future.

First, we must simulate the test before creating a tool class. In this example, the process is as follows:

1: Introduce Oracle drivers

2: Create an OracleTools class and define its member variables.

3: Write the member methods and constructors of the OracleTools class.

4: If all tests are successful, the jar package is generated.

It is reasonable to say that after these four steps, all of them should be done, but the problem is very strange. There is no problem in the simulation, once the jar package is generated and put into other classes, the exceptions I wrote in the jar package are not displayed. Obviously, the problem occurs at the beginning, I checked the code carefully and found no problem. I suddenly understood whether it was a character encoding problem. So I took a lot of effort to modify the character encoding and then went to the test tool class, but unfortunately, I still cannot. What is the problem? Will it be a problem with the java Runtime Environment, So I re-built a project and re-deployed it according to the previous steps. Damn it, I can finally! In this case, different jre running results may cause errors. Generally, you can run the Environment Bureau with your own installed resources without creating tools. This problem can be solved, looking at the problems may not necessarily be in the places you often think of, but also outside of your understanding. Therefore, you should look at the problems in the future.

Let's not talk about it much. Below are the attributes of my tool class:

Class Name: Two: OracleTools and MysqlTools. Therefore, this jar package supports both Oracle and Mysql databases.

Member variable: If you know the name, you will not comment it out...

Private static String Host;
Private static String UserName;
Private static String Password;
Private static String ports = "1521 ";
Private static String DbName;
Private static String SQL;
Private static Connection Conn = null;
Private static PreparedStatement St = null;
Private static ResultSet Res = null;
Private static int dml_res;

Constructor:

OracleTools (String host, String username, String password, String dbname );

MysqlTools (String host, String username, String password, String dbname );

Member method:

Execute_dql (); // database query method

Execute_dml (); // Database Operation Method

Close (); // Close various resources

Here is the required tool class and database driver

Related Article

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.