我一直试图运行这段代码几个小时,但没有成功。我有Oracle 11g企业版。有没有人知道从sql * plus cmd提示符获取端口号的代码? 代码没有运行,我无法通过eclipse查看输出。请指导我。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Testt {
public static void main(String[] args) throws Exception {
try{
//Driver registration
Class.forName("oracle.jdbc.driver.OracleDriver");
//Create connection
Connection c =DriverManager.getConnection("jdbc:oracle:thin:
@localhost:1521:EE","scott","tiger");
//Create statement
Statement stmt=c.createStatement();
//Execute query
ResultSet rs=stmt.executeQuery("select * from emp;");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
c.close();
}
catch(Exception e){e.printStackTrace();}
}
}
输出: java.sql.SQLException:Listener拒绝连接时出现以下错误: ORA-12505,TNS:监听器当前不知道连接描述符
中给出的SID