Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

java - how can i resolve-oracle-11g-xe using eclipse

rule for tcp port 1521I am trying to make a sample JDBC program i which i have to create table but i am facing this issue i tried many solution present on web all i have to come to know that service is missing but did not find exact solution i am beginner in JDBC any help will be appreciated.

My JDBC program:-

import java.sql.*;


public class JdbcExample {

/**
 * @param args
 * @throws ClassNotFoundException 
 * @throws SQLException 
 */
public static void main(String[] args) throws ClassNotFoundException, SQLException {
    // TODO Auto-generated method stub
    String userName="system",password="admin",url="jdbc:oracle:thin:localhost:1521:xe";
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con =  DriverManager.getConnection(url, userName, password);
    System.out.println(con);
    Statement stmt = con.createStatement();
    System.out.println(stmt);
    int b = stmt.executeUpdate("create table emp(eno number(5),name varchar2(20));");
    System.out.println("Table Created" + b);
    //      if(b)
    //      {
    //          
    //      }
    //      else
    //          System.out.print("WTF");


}

My LogCat:-

java.sql.SQLException: Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=186646784)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JdbcExample.main(JdbcExample.java:19)

My listener.ora

SID_LIST_LISTENER = (SID_LIST =
(SID_DESC =
  (SID_NAME = PLSExtProc)
  (ORACLE_HOME = J:apporacleproduct11.2.0server)
  (PROGRAM = extproc)
)
(SID_DESC =
  (SID_NAME = CLRExtProc)
  (ORACLE_HOME = J:apporacleproduct11.2.0server)
  (PROGRAM = extproc)
))LISTENER =(DESCRIPTION_LIST =
(DESCRIPTION =
  (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
))DEFAULT_SERVICE_LISTENER = (XE)

Thanks In advance. NOTE : I have included ojdbc14_g.jar file in my buildconfig.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try changing from:

"jdbc:oracle:thin:localhost:1521:xe"

to:

"jdbc:oracle:thin:@//localhost:1521/XE"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...