Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6872761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:58:13+00:00 2026-05-27T03:58:13+00:00

I want to create database at the first time of an application deploying process.

  • 0

I want to create database at the first time of an application deploying process. I am using JPA. So I consider two ways.

1) I have a full connection description in my persistence.xml:

<property name="mysql.jdbc.user" value="root"/>
<property name="mysql.jdbc.password" value=""/>
<property name="mysql.jdbc.url" value="jdbc:mysql://localhost:3306/DB"/>
<property name="mysql.jdbc.driver" value="com.mysql.jdbc.Driver"/>

When an application is started, it cannot connect to DB and reports about this trouble advising to go to the install page. In this install page I launch a DB creation with explicit SQL queries.

2) I have a connection to a database server:

<property name="mysql.jdbc.user" value="root"/>
<property name="mysql.jdbc.password" value=""/>
<property name="mysql.jdbc.url" value="jdbc:mysql://localhost:3306/"/>
<property name="mysql.jdbc.driver" value="com.mysql.jdbc.Driver"/>

An application informs me that it is a first conneciton and redirect me to the install page. During a DB installation persistence.xml should be modified. The property mysql.jdbc.url must be changed a new value assignment which declares a database name.

What do you think about this? How to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:58:14+00:00Added an answer on May 27, 2026 at 3:58 am

    What you could do is add a servlet that is configured to run (once) at application startup. This servlet could check whether the database already exists and if not, create it programmatically. Check this question’s answers to see how this can be achieved for MySQL. If you have a running server, you can obtain a connection and run the SQL to create the database. After that, the necessary tables and the like can be auto-created using the right property for your JPA implementation (like Nulldevice showed for Hibernate).

    You could even have the servlet locate the persistence.xml file, since it’s supposed to be in a particular location anyway, and parse it to find out several properties like URL to make sure they’re only defined in one place.

    What I’m not certain about is whether JPA would only try connecting (and possibly creating the tables) after the servlet is run, or how this could be forced. For this, you might have to check the lifecycle of JavaEE applications. It could depend on the implementation by the Application Server vendor too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working with sqlite database in Android for first time. i have create
i want to create tabs according to data from MySQL database using php for
I want my code to automatically try multiple ways to create a database connection.
I have some data I load into the database the first time a user
I want to create a database in which there's an n x m relationship
Ok, so I want to create a database with all the data of the
I want to create a large database of GPS coordinates that can be queried
I want to create a new row in my database on a table that
I want to create a SQL Server Express database on my local machine and
I want to create a trace on a database server from my C# app,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.