#making a little sql api

1 messages · Page 1 of 1 (latest)

edgy lance
#

HIi, I have a main application and for other applications, I want to provide an sql connecion using an api. Like this, and other app we don't have to write directly sql request and don't have to manage connection. juste calling a method. But is complexe because we have a lot of parameters. I have an idea but I am note sur that is the best.

here is an example of the methode to make a select:
(Wheretype is an enum with all where type like "between", "like", "and" etc...)
the arraylist contain values in the where instruction. for example here the wheres_values contain age, 10 and 20

SELECT PLAYER
FROM T
WHERE age BETWEEN 10 AND 20;


selectQuerySql(ArrayList<String> selects, String from, WhereTypeEnum wheretype, ArrayList<Integer> where_values)```
is a good implmentation? thanks
timber archBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
HIi, I have a main application and for other application, provide an sql connecion using an api. Like this, and other app we don't have to write directly sql request and don't have to manage connection. juste calling a method. But is complexe because we ha

have direct access to the database. Can you guide me on how to create a simple SQL API in Java?

Sure! To create a simple SQL API in Java, you can follow these steps:

  1. Start by creating a Java class that will serve as the API for interacting with the database. This class will contain methods for connecting to the database, executing queries, and handling results.

  2. Use JDBC (Java Database Connectivity) to establish a connection to your database. You will need to provide the necessary connection details such as the database URL, username, and password.

  3. Implement methods in your API class for executing SQL queries such as SELECT, INSERT, UPDATE, and DELETE statements. These methods should take SQL queries as parameters and return the results of the query.

  4. Consider using PreparedStatement to prevent SQL injection attacks and improve performance when executing multiple queries.

  5. Handle exceptions properly by catching SQLExceptions and logging or returning appropriate error messages.

  6. Finally, test your SQL API by writing some sample code that uses the API to connect to the database, execute queries, and retrieve results.

By following these steps, you can create a simple SQL API in Java that provides an abstraction layer for interacting with your database from other applications without directly writing SQL queries.

weak wedge
#

so basically you are trying to reimplement Hibernate's Criteria api

#

look into it

edgy lance
#

ah yes

#

and my architectury is good?

#

is not exactly same but its in the same "idea"

brazen bone
brazen bone
edgy lance
edgy lance
# brazen bone wdym

I just say, maybe is better to dont make an api and just provid sql connection

weak wedge
#

provide an API for concrete goals

#

don't try yo fully wrap an entire criteria API

edgy lance