0

We have 2 projects with the same database using JAVA Spring-boot. The main projects hold the entity and repository files. Which is different to the other project. Since we don't understand the whole system of the main project we create ours. The problem is I need to get the data from a table without using repositories function like get, save, etc. I just need to query the table. Is this possible?

Thank you.

MCSanie
  • 11
  • 4

2 Answers2

0

Depends on what you want

  • Only simple Data
  • A complete Object representing the data or part of the data

For the first one I would take JDBC(https://www.javatpoint.com/java-jdbc)

For the second one I would take JPA/Hibernate. You can create a Entity which represents only the data you need and make it read-only(How to make an Entity read-only?).
And then you can create a simple CrudRepository/JpaRepository where you fetch the data.

  • is the second one safe to use without creating or deleting data in the database or affecting other codes? – MCSanie Mar 27 '19 at 10:33
  • it should be, because if the entity is read-only (save or delete will not take effect). if you create a complete new Entity and use it only in your case, there will be no impact on other code. For example: I did this once with a really big Entity, where it was not allowed to change the DB-Structure. So I created a "SmallEntity" for all the search Fields. And the rest of the code worked as before – metalhead666 Mar 28 '19 at 10:22
0

Here's some pointers for your help: DB Name/Host/User/Pass should be found in one of the *.properties files.

  • In Repositories, the table names are usually with @Table annotation.
  • To know what Queries a particular repository can execute, you can check with @Query annotation. Or the methods inside the repository may donate queries, like findByStudentId means select from student where id=.

Now with the above clues, you can just write a simple JDBC connection (it really depends on what db it is in the backend), connect to the DB above, and execute the queries you may want to.

Shariq
  • 513
  • 4
  • 14