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 8966781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:05:45+00:00 2026-06-15T17:05:45+00:00

Currently I am importing a database dump file sample.sql to the application. I need

  • 0

Currently I am importing a database dump file sample.sql to the application. I need to import the database and append to the existing tables since the database contains same tables and fields.

How can I solve the issue? What is the command to append the imported database to existing database?

The code to import file

try {

    String[] command = new String[]{"\""+this.m_MySqlPath+"mysql\"", Constants.DB_NAME, "-u" + Constants.DB_USER, "-p" + Constants.DB_PASSWORD, "-e", " source "+"\""+FileName+"\"" };
    Process runtimeProcess = Runtime.getRuntime().exec(command, null, new File(this.m_MySqlPath));
    int processComplete = runtimeProcess.waitFor();

    if (processComplete == 0)
    {
        System.out.println("DatabaseManager.restore: Restore Successfull");
    }
    else 
    {
        System.out.println("DatabaseManager.restore: Restore Failure!");
    }
  • 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-06-15T17:05:46+00:00Added an answer on June 15, 2026 at 5:05 pm

    Assume your script is “myscript.sql” and its stored in “c:\” then following command can be used to import that script to your database

    c:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe --host=127.0.0.1 --user=root --password=root < c:/myscript.sql
    

    This same command can be used in Runtime.getRuntime().exec . But when i tried there is some simple issues and its not working properly.So i used another method.

    Before that i am assuming that your database script contain more data than in database. So even if i delete database and then import database using database script , i dont loss any data. I am just dropping(removing) current database and importing database from your database script file.

    To solve above mentioned Runtime.getRuntime().exec , i created a batch file named “ba.bat” . And stored that batch file in c: drive as “c:\bat.bat”. Content of that batch file is given below

    %1\mysql.exe --host=%2 --user=%3 --password=%4 < c:/myscript.sql
    exit
    

    You can call with following syntax ba.bat arg1 arg2 arg3 arg4

    where arg1=path to mysql bin folder example =c:\Program Files\MySQL\MySQL Server 5.1\bin
    arg2=mysql host ip address
    arg3=mysql username
    arg4=mysql password

    And the final java program is given below

    import java.sql.*;
    
    public class NewClass {
    
        public static void main(String[] args) {
            Connection conn = null;
          String mysqlPath="c:/Program Files/MySQL/MySQL Server 5.1/bin";
            String url = "jdbc:mysql://192.168.100.86/";
            String databaseIp="192.168.100.86";
            String dbName = "databasename";
            java.sql.Statement stmt = null;
            String query = "";
            ResultSet result = null;
            String driver = "com.mysql.jdbc.Driver";
            String userName = "root";
            String password = "root";
            try {
                Class.forName(driver).newInstance();            
                conn = DriverManager.getConnection(url , userName, password);
                stmt = conn.createStatement();
                result = null;
                String test,input;
                stmt.execute("drop database if exists  "+dbName);
                String fullPathWithArgs ="C:/ba.bat \""+mysqlPath+"\" "+databaseIp+" "+userName+" "+password+"";
                Process runtimeProcess =Runtime.getRuntime().exec(fullPathWithArgs);
                int processComplete = runtimeProcess.waitFor();
                if (processComplete == 0)
                          {
                               System.out.println("DatabaseManager.restore: Restore Successfull");
                          }
                else
                      {
                         System.out.println("DatabaseManager.restore: Restore Failure!");
                      }
    
                conn.close();
            } catch (Exception e) {           
                System.out.println("exception: " + e.getMessage());
            }
        }
    }
    

    In the above java program i am dropping database and importing database from script.
    You must use CREATE DATABASE IF NOT EXISTS in your script.From your question i felt this is what you want. Please let me know in case of any problem or above is not your expected answer.

    One more thing if you want to append data to existing database then please delete

    stmt.execute("drop database if exists  "+dbName);
    

    from java code and also make the required column in your database table to ‘unique’ ie.. create unique index for required table columns

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

Sidebar

Related Questions

I have a large database dump.sql file I am importing from the command line
i have a .sql file which contains the exported code from some database #
I have a large sql dump file ... with multiple CREATE TABLE and INSERT
I need your suggestions please, I'm currently using the Magento API for importing products
I am currently working with a Joomla 1.6 install and need to import about
I'm currently building a system with Ms Access. Since it's important to avoid sql
I have server that needs to process and dump from an SQL database queries
I currently have a large number of CSVs to import to a MySQL database.
I am currently doing a *cough*Oracle*cough* database subject. The lecturer is introducing embedded SQL
Currently I have an application that takes information from a SQLite database and puts

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.