【问题标题】:Connection with Java Spring, maven, oracle, hibernate与 Java Spring、maven、oracle、hibernate 连接
【发布时间】:2018-11-22 13:27:16
【问题描述】:

我正在尝试使用 spring 和 hibernate 将我的 maven 项目连接到 oracle 数据库,经过多次尝试修复它后仍然出现此错误,你们介意检查一下并指导我可能出了什么问题吗?

Error in CMD (Picture)

23:07:45,676 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringMVC].[SpringMVC]] (http--127.0.0.1-8088-1) Servlet.service() para servlet SpringMVC lanz¾ excepci¾n: oracle.net.ns.NetException: Got minus one from a read call

我的应用程序上下文: ApplicationContext.xml (picture)

<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
    <property name="dataSourceName" value="ds" />
    <property name="URL"
        value="jdbc:oracle:thin:@127.0.0.1:8080:test" />
    <property name="user" value="system" />
    <property name="password" value="3123312257" />
</bean>

我对 Oracle 的依赖

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>12.1.0.2</version>
</dependency>

我的应用程序属性:

# create and drop tables and sequences, loads import.sql
spring.jpa.hibernate.ddl-auto=create-drop

spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:8080:test
spring.datasource.username=system
spring.datasource.password=3123312257
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

# logging
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
logging.level.org.hibernate.SQL=debug

【问题讨论】:

  • oracle 的端口通常是 1521,Web 应用程序是 8080...当您使用 oracle sql 客户端连接到它时,请检查 yoyr oracle db 的端口...
  • 虽然没有任何堆栈跟踪,但无法说出明确的原因......
  • @akshayapandey 是的,我将端口更改为 1521,现在显示以下错误:
  • 23:55:49,597 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringMVC].[SpringMVC]] (http--127.0.0.1-8088-1) Servlet.service() para servlet SpringMVC lanz¾ excepci¾n: oracle.net.ns.NetException: Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
  • 您应该验证您的 SID 'test' 是否存在于 oracle 中。默认值通常是 XE。 conenctio 字符串的格式为 jdbc:oracle:thin:@::

标签: java oracle hibernate maven spring-mvc


【解决方案1】:

将端口更新为 1521 后,您可能需要在 tnsnames.ora 中更新端口(可能放在 oracle\product\{version}\client_1\network\ADMIN 中)。

【讨论】:

    【解决方案2】:

    主机“localhost”和端口“8080”的连接参数真的正确吗?

    请验证一次。

    下面的代码对我来说很好。您可以使用它并检查是否存在 oracle 问题或您的问题。

    public static void main(String[] args) throws ClassNotFoundException {
    try {
    Connection connection = null;
    
    String serverName = "127.0.0.1"; //http://127.0.0.1:8080/apex
    String portNumber = "1521";
    String sid = "xe"; //xe
    
    String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
    
    String username = "system";
    String password = "password";
    
    connection = DriverManager.getConnection(url, username, password);
    
    Statement stmt = connection.createStatement();
    
    ResultSet rset = stmt.executeQuery("select * from employee");
    
    while (rset.next()) 
    {
    System.out.println(rset.getString(1));
    System.out.println(rset.getString(2));
    }
    stmt.close();
    
    } catch (Exception e) {
    System.out.println("Hai " + e);
    }
    }
    

    【讨论】:

    • 我将端口改为1521,现在显示如下错误:23:55:49,597 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringMVC].[SpringMVC]] (http--127.0.0.1-8088-1) Servlet.service() para servlet SpringMVC lanz¾ excepci¾n: oracle.net.ns.NetException: Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
    • 太棒了!非常感谢!!在您的帮助下,我解决了最大的问题
    猜你喜欢
    • 2012-07-08
    • 2017-08-20
    • 2016-12-10
    • 2016-01-27
    • 1970-01-01
    • 2013-01-09
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多