当前位置: 首页 > 知识库问答 >
问题:

无法提取结果集:hibernate,oracle数据库中的SQL语法异常

顾俊茂
2023-03-14

请帮我解决这个问题。这是我错误的堆栈跟踪。

Servlet。路径为[]的上下文中servlet[DispatchersServlet]的服务()引发异常[请求处理失败;嵌套异常为org.springframework.dao.InvalidDataAccessResourceUsageException:无法提取结果集;SQL[n/a];嵌套的异常是org。冬眠例外SQLGrammarException:无法提取具有根本原因的ResultSet]

oracle.jdbc.:表或视图不存在

这是员工。java类。

package com.example.demo.model;


import javax.persistence.*;
import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;


@Entity
@Table(name = "demo_employee1")

public class Employee implements Serializable {


    private static final long serialVersionUID = 2L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "s_employeeCreate")
    @SequenceGenerator(name = "s_employeeCreate", sequenceName = "s_employeeCreate", allocationSize = 1)
    @Column(name = "id", unique = true, nullable = false)
    private Long id;


    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "email_address")
    private String email;

    @Column(name = "employee_DepartmentId")
    private String employeeDepartmentId;


    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;

    }

    public String getEmployeeDepartmentId() {
        return employeeDepartmentId;
    }

    public void setEmployeeDepartmentId(String employeeDepartmentId) {
        this.employeeDepartmentId = employeeDepartmentId;
    }


}

这是雇主的要求。JAVA

package com.example.demo.DTO;

import com.fasterxml.jackson.annotation.JsonProperty;

import com.example.demo.model.Employee;

import org.springframework.beans.BeanUtils;

public class EmployeeDTO {

    @JsonProperty(value="id")
    private long id;

    @JsonProperty(value="firstName")
    private String firstName;

    @JsonProperty(value="lastName")
    private String lastName;


    @JsonProperty(value="email")
    private  String email;


    @JsonProperty(value="employeeDepartmentId")
    private String employeeDepartmentId;



    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }
    public  String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmployeeDepartmentId(){
        return employeeDepartmentId;
    }

    public void setEmployeeDepartmentId(String employeeDepartmentId){
        this.employeeDepartmentId= employeeDepartmentId;
    }


    public static Employee valueOf(EmployeeDTO employee) {
        if (employee != null) {
            Employee employee1 = new Employee();


            employee1.setFirstName(employee.getFirstName());
            employee1.setLastName(employee.getLastName());
            employee1.setEmail(employee.getEmail());
            employee1.setEmployeeDepartmentId(employee.getEmployeeDepartmentId());




            return employee1;
        }
        return null;
    }


 public static EmployeeDTO valueOf(Employee employee) {
        EmployeeDTO employeeDTO = new EmployeeDTO();
        BeanUtils.copyProperties(employee, employeeDTO);
        return employeeDTO;
    }

    public static Employee valueOf1(EmployeeDTO employeeDTO) {
        Employee employee = new Employee();
        BeanUtils.copyProperties(employeeDTO, employee);
        return employee;
    }
    @Override
    public String toString() {
        return "EmployeeDTO{" +

                " firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ",email='"+ email+'\''+
                ", EmployeeDepartmentId=" + employeeDepartmentId +
                '}';
    }


}

这是员工服务。java类。

package com.example.demo.Service;

import com.example.demo.model.Employee;
import com.example.demo.DTO.EmployeeDTO;
import com.example.demo.Repositry.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.ArrayList;
import org.springframework.util.CollectionUtils;


import java.util.Optional;


@Service
public class EmployeeService {

    @Autowired EmployeeRepository employeeRepository;

    @Autowired EmployeeService employeeService;

    Logger LOG = LoggerFactory.getLogger(EmployeeService.class);

    public Employee createEmployee(EmployeeDTO employeeDTO) {
        LOG.info(employeeDTO.toString());
        Employee employee = EmployeeDTO.valueOf1(employeeDTO);
        LOG.info(employee.toString());
        return employeeRepository.saveAndFlush(employee);
    }

    public EmployeeDTO getUserById(Long id) {
        Employee employee = employeeRepository.findById(id).orElse(null);
        if (employee != null) {
            return EmployeeDTO.valueOf(employee);
        }
        return null;
    }

    public List<EmployeeDTO> getAllUsers() {
        List<Employee> employees = employeeRepository.findAll();
        List<EmployeeDTO> employeeDTOList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(employees)) {
            for (Employee employee: employees) {
                employeeDTOList.add(EmployeeDTO.valueOf(employee));
            }
        }
        return employeeDTOList;
    }


}

这是员工控制员。java类

@Controller
public class EmployeeController {
    Logger LOG = LoggerFactory.getLogger(EmployeeController.class);


 @Autowired
    private EmployeeService employeeService;

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ResponseBody
    public String testApi() {
        return "Hello World";
    }

    @RequestMapping(value = "/employee/create", method = RequestMethod.POST)
    @ResponseBody
    public String createEmployee(@RequestBody EmployeeDTO employeeDTO) {
        LOG.info("create Employee");
        Employee employee = employeeService.createEmployee(employeeDTO);
        if (employee != null) {
            return "Successfully created user with " + employee.getFirstName() + " " + employee.getLastName();
        }
        return "Failed to create user";
    }

    @RequestMapping(value = "/user/read", method = RequestMethod.GET)
    @ResponseBody
    public EmployeeDTO getUser(@RequestParam Long id) {
        LOG.info("get user");
        return employeeService.getUserById(id);
    }

  

      @RequestMapping(value = "/user/all", method = RequestMethod.GET)
        @ResponseBody
        public List<EmployeeDTO> getAllUsers() {
            LOG.info("get all users");
            return employeeService.getAllUsers();
        }
    }

共有1个答案

廖永长
2023-03-14

我不知道您使用的工具,但是-如果:

@Table(name = "demo_employee1")

代表一个你想使用的表,然后甲骨文抱怨说

ORA-00942:表或视图不存在

然后:在Oracle中,对象名称默认存储为大写,所以尝试DEMO_EMPLOYEE1而不是demo_employee1

如果不是这样,那么检查是否

  • 您使用的表实际上存在于您连接到的Oracle架构中
 类似资料:
  • 我得到异常后,我适当的结果criteria.unique结果()对象报价。目的查询-从数据库Oracle的表“报价”中获得随机结果 org.hibernate.exception.SQLGrammarExc0019:无法提取org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelega

  • 我的存储库中有nativeQuery查询。 但是当我运行这个页面时,我有一个错误 无法提取结果集;SQL[n/a];嵌套的异常是org。冬眠例外SQLGrammarException:无法提取结果集 产业 能找个人帮我吗。或者如何将这个nativeQuery转换为Hibernate sql?谢谢

  • 我有一个PHP应用程序,需要查询MicrosoftSQL数据库。这很容易,但是我很难从结果集中获得“num_rows”...这是我的代码,以及我尝试过的一些东西——任何帮助都值得赞赏! 我知道$rs持有数据,因为我可以通过以下方式成功地将数据拉出来:

  • 我有一个与Oracle数据库应用程序连接的Spring Boot。同一版本的应用程序在MySQL上运行良好,但当我尝试对Oracle数据库执行一些请求时,它会抛出错误: Servlet.service()的servlet[调度Servlet]在上下文与路径[]抛出异常[请求处理失败;嵌套异常org.springframework.dao.InvalidDataAccessResourceUsage

  • 我想得到分数和日期列在给定范围内的条目数,按分数间隔分组。分数间隔由给定的粒度决定。所以我想回答的问题是:在给定的时间段内,有多少结果的分数在0-25、26-50、56-75等之间。。。在这种情况下,粒度为25。 以下本机SQL查询将生成所需的结果: 我想用自己的查询定义一个查询方法,使用注释。 它是一个简单的bean,它不是一个实体。 我得到以下例外: 组织。springframework。刀。

  • 在过去的一周里,我一直试图在电脑上学习MySQL。我有一个名为用户的数据库和一个名为用户的表,表中有数据。但是我下面有这个PHP代码,它不会得到任何结果,我不知道为什么。