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