简体   繁体   English

与Java Spring,Maven,Oracle,Hibernate的连接

[英]Connection with Java Spring, maven, oracle, hibernate

I'm trying to connect my maven project to an oracle database using spring and hibernate, this error is still showing up after many attempts to fix it, would you guys mind checking this out and guide me on what might be wrong? 我正在尝试使用Spring和Hibernate将Maven项目连接到oracle数据库,在多次尝试修复该错误后仍会显示此错误,你们是否介意对此进行检查并指导我可能出了什么问题?

Error in CMD (Picture) CMD错误(图片)

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

My Application context: ApplicationContext.xml (picture) 我的应用程序上下文: ApplicationContext.xml(图片)

<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>

My dependecy of Oracle 我对Oracle的依赖

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

My aplication.properties: 我的aplication.properties:

# 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

The connection parameter for host "localhost" and the port "8080" are really correct? 主机“ localhost”和端口“ 8080”的连接参数是否正确?

Please verify once. 请确认一次。

Below code works fine for me. 下面的代码对我来说很好。 you can use the same and check if there is an oracle issue or your side. 您可以使用相同的工具,并检查是否有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后,您可能需要更新tnsnames.ora中的端口(可能放在oracle \\ product \\ {version} \\ client_1 \\ network \\ ADMIN中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM