Results 1 to 10 of 10
  1. #1
    me.anchit is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Post How to create database through java program.??

    hello everyone,

    I have made an application in swing which uses MySQL database. Now I want that whenever my app is made to run on a new system for the first time, the app asks for the ip and port number of mysql from the user and creates the database and its tables automatically. Besides I have created a user in mysql, so it must create it accordingly. This should happen only for the first time.

    How can it be done through java...????

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    By using a db user that has those rights and using sql commands.

  3. #3
    me.anchit is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    ok, I got it....
    thank you.
    but can anyone tell me the logic that how the program is going to know that it is running for the first time on a system...???
    Regards

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Check if any of the tables exist?

  5. #5
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    You have several options, one is using the standard JDBC connection(non-hibernate) and the using Hibernate.

  6. #6
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default

    Hi everybody......

    I have same problem, but I want to create MS Access 2007 (.accdb) database. When my application will run for the first time, the database should be create with some tables.


    I have tried by following code, it created .accdb database, but when I tried to open the database it shows unknown access format.

    Java Code:
    FileOutputStream file = new FileOutputStream("databasename.accdb");

    How can I do it?

    Thank you.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Unless Access provides you with an interface in Java to create a database then you won't be able to do it.
    Either that or you'll have to rely in there being an existing access database you can add tables to.

    Which reminds me, is there a proper JDBC driver for Access?
    If you are using the JDBC-ODBC bridge then that's another big problem.

  8. #8
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Unless Access provides you with an interface in Java to create a database then you won't be able to do it.
    Either that or you'll have to rely in there being an existing access database you can add tables to.

    Which reminds me, is there a proper JDBC driver for Access?
    If you are using the JDBC-ODBC bridge then that's another big problem.
    Thank you for your reply.

    I don't know, but is there any interface of access for database creation?

    And except JDBC-ODBC bridge how can I connect with database using java?
    Please give me a sample code.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    I only know of the bridge for access. I don't use Access, so can't say if there's a "proper" driver.

    As for creating the db file via Java, you'll have to do some hunting, but I very much doubt you'll find anything that does it.

    Why not use something like Derby instead? A proper Embedded database (presuming it's not for multiple users).

  10. #10
    mitra is offline Member
    Join Date
    Jun 2011
    Posts
    59
    Rep Power
    0

Similar Threads

  1. Java Barcode Program with Oracle database
    By techsing14 in forum Java 2D
    Replies: 4
    Last Post: 02-25-2011, 07:37 AM
  2. Replies: 2
    Last Post: 08-13-2010, 11:42 AM
  3. Replies: 1
    Last Post: 05-05-2010, 03:26 AM
  4. Create a folder within a java program.
    By yellowfire7 in forum New To Java
    Replies: 2
    Last Post: 10-26-2009, 10:14 PM
  5. Replies: 2
    Last Post: 06-12-2008, 07:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •