Java Operations Oracle Database self-built tool library

Source: Internet
Author: User

When learning the Java operation of the Oracle database, it occurred to me that it would be possible to build a tool class like PHP, which would greatly reduce the complexity of the code. can also improve productivity.

Java If you can not build a tool class, it is very ridiculous, but, in the process of establishment, there are some problems, I hope in the future do not make similar mistakes.

First of all, we must first simulate the test before we build the tool class, in this example, the process is as follows:

1: Introduction of Oracle Drivers

2: Establish the Oracletools class and define its member variables.

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

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

According to reason, after the four, it should be all done, but the problem is very strange, there is no problem in the simulation, once the jar package into another class inside is completely not, so that I write in the exception is not displayed, it is obvious that the problem appeared in the beginning, I carefully examine the code, Still did not find out what the problem, suddenly understand, is not the problem of character encoding, so the waste of a great effort to modify the character encoding, and then to test the tool class, but unfortunately, still can not, exactly where is the problem? Will not be the Java running environment problem, so I re-establish a project, and then follow the previous steps to redeploy, Mom, finally can! In this sense, the results of different JRE runs may be wrong, in general, with their own installed amount of the operating Environment Bureau can, do not establish the use of tools, there is such a problem can end, look at the problems that arise, not necessarily in the place you often think of, but also may be in your understanding, so, later on the problem, There are more aspects to see.



Not much to say, here is my tool class property:

Class Name: Two: Oracletools and mysqltools so this jar package can support both Oracle and MySQL databases

Member variables: See the name, do not comment ...

private static String Host;
private static String UserName;
private static String Password;
private static String port= "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;

Construction Method:

Oracletools (String host,string username,string password,string dbname);

MYSQLTools (String host,string username,string password,string dbname);

Member Methods:

EXECUTE_DQL (); //Database Query method

Execute_dml (); //Database operation methods

Close (); //close various resources


Here is the required tool class as well as the database driver

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Operations Oracle Database self-built tool library

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.