How to connect ecplise and myecplise to the oracle database

Source: Internet
Author: User

How to connect ecplise and myecplise to the oracle database
Ecplise connect to database 1. Import jar package

For the oracle version of GB, find the corresponding jar in the following directory and import it to the project runtime environment.

Ojdbc6.jar under app \ oracle \ product \ 11.2.0 \ dbhome_1 \ jdbc \ lib

App \ oracle \ product \ 11.2.0 \ client_1 \ oui \ jlib \ classes12.jar

2. Create a jdbc class and perform the following operations:
Package com_it_JDBC; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. SQLException; import java. SQL. statement; import java. util. concurrent. countDownLatch; public class JdbcDemo {public static void main (String [] args) {// defines the oracle database Driver class String driverclass = "oracle. jdbc. oracleDriver "; // define the Url String url to connect to oracle =" jdbc: oracle: thin: @ 192.168.0.1: 1521/orcl "; // login username String usern Ame = "admin"; // password String password = "root"; Connection conn = null; Statement stmt = null; ResultSet rs = null; string querysql = "select * from person"; try {// register the database driver and load the Class into the memory Class. forName (driverclass); // obtain the database connection conn = DriverManager. getConnection (url, username, password); // create an SQL Execution object stmt = conn. createStatement (); // execute the SQL statement rs = stmt.exe cuteQuery (SQL); // call the getMetaData method to obtain ResultSetMet The method // In the aData interface gets the number, type, and attribute of the column of the ResultSet object. // Obtain the metadata of the current table: Table name, which lists the number of columns. ResultSetMetaData rsm = rs. getMetaData (); // obtain the number of columns Integer col = rsm. getColumnCount (); System. out. println ("columns:" + col); ArrayList <String> list = new ArrayList <> (); for (int I = 1; I <= col; I ++) {// obtain the column name String cs = rsm. getColumnName (I); list. add (cs);} // obtain the data corresponding to the column while (rs. next () {for (String cname: list) {String val = rs. getString (cname); System. out. print (cname + ":" + val) + "");} System. out. println () ;}} catch (Exception e) {e. printStackTrace () ;}finally {try {if (rs! = Null) {rs. close () ;}if (stmt! = Null) {stmt. close ();} if (conn! = Null) {conn. close () ;}} catch (SQLException e) {e. printStackTrace ();}}}}
3. jdbc configuration of myecplise

As shown above;

The difference is that the URL format is different.

''

String url = "jdbc: oracle: thin :@ localhost: 1521: orcl (sid );

''

4. Several Common Errors:

1. IO exception: Connection refused (DESCRIPTION = (TMP =) (VSNNUM = 186647552) (ERR = 12505) (ERROR_STACK = (ERROR = (CODE = 12505) (EMFI = 4 ))))

Solution: run the following statement in the database to be connected:

Select INSTANCE_NAME from v $ instance; change sid to the running result.

2. Io exception: Invalid connection string format, a valid format is: "host: port: sid"

URL format problem: myecplise is in the following format:

Jdbc: oracle: thin: @ localhost: 1521: orcl

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.