Ever wished you could just ask for the SQL query you need instead of writing it? In this project, I built a Java-based backend that lets you do exactly that.
๐ Project Repo
Check out the full code on GitHub:
๐ github.com/amkumar072/AI-SQL-Generator
๐งฉ What Is It?
AI-SQL Generator is a backend application that transforms natural language prompts into SQL queries using OpenAI's GPT API. Itโs perfect for:
- Developers building analytics dashboards
- Business users who arenโt fluent in SQL
- Teams needing AI-driven query interfaces
๐ How It Works
You send a POST request with:
- A natural language prompt
- The table schema (as a SQL
CREATE TABLEstring)
And you get back a GPT-generated SQL query that's ready to use.
๐ฆ Sample Request
POST /query
Content-Type: application/json
{
"question": "Which seller has delivered the most orders to customers in Rio de Janeiro"
}
โ Sample Response
{
"sql": "SELECT * FROM Employee ORDER BY salary DESC LIMIT 5;"
}
๐ง Tech Stack
| Layer | Tech Used |
|---|---|
| Language | Java 17 |
| Framework | Spring Boot |
| API | OpenAI GPT (via HTTPS) |
| Config | dotenv-java for secrets |
| Build Tool | Maven |
| Testing | Postman / curl |
โ๏ธ Setup Instructions
- Clone the repo:
git clone https://github.com/amkumar072/AI-SQL-Generator.git
cd AI-SQL-Generator
- Add your OpenAI key to a
.envfile:
OPENAI_API_KEY=your_openai_api_key
- Run the Spring Boot app:
mvn spring-boot:run
๐ Example Use Cases
- ๐ Internal tools for data analysts
- ๐ง Chatbot assistants that answer data questions
- ๐ฅ๏ธ AI dashboards for business users
- ๐ ๏ธ Dev platforms embedding auto-SQL features
๐ Whatโs Next?
Here are a few potential enhancements:
- UI frontend with React or Angular
- Support for SQL dialects (MySQL, PostgreSQL, etc.)
- Real-time database validation for generated SQL
๐ง Why I Built This
The idea came from a common pain point: not everyone can write SQL, but everyone needs data. Tools like ChatGPT already understand data requests wellโwhy not bring that power into a dedicated backend app?
This project combines the reliability of Java/Spring Boot with the intelligence of OpenAI GPT to deliver something actually useful for devs and data teams alike.
๐ฌ Letโs Connect
If you liked this or have ideas to improve it, feel free to:
#java #springboot #openai #sql #gpt #api #backend #ai #devtools #projectshowcase
Top comments (0)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.