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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:35:18+00:00 2026-05-16T05:35:18+00:00

Is there a way to programatically import an entire database from a file with

  • 0

Is there a way to programatically import an entire database from a file with SQL?? (either .CSV , .SQL and .DB files are fine)

Thanks!!

EDITED AFTER TO CLARIFY:

I am interested in a solution that is Database independent (has to works with all types of databases (Mysql, SQL Server, PostGres, Oracle…)

  • 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-16T05:35:18+00:00Added an answer on May 16, 2026 at 5:35 am

    Ok so I actually found a solution that is Database INDEPENDENT to import a database from a .Sql file quite easily!! 🙂

    So whichever database you have (Mysql, Sqlite, …) do the following:

    1) export your database into .sql format.
    (This .sql file will contain all sql commands such as CREATE TABLE… INSERT INTO table…)
    (You may need to remove the lines that start with CREATE TABLE and leave only the lines that start with INSERT…)

    2) Then in the language that you are using write some code that read each line of the Sql Lite files and stores it into an Array of String (String[])

    3) Then execute each String contained in the array String[] as sql command

    I’ve implemented this in Java:

    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.util.LinkedList;
    import java.util.List;

    import android.content.Context;
    import android.database.sqlite.SQLiteDatabase;

    public class DatabaseImporter {

    private static DatabaseImporter instance;

    public static DatabaseImporter getInstance(){
    if(DatabaseImporter.instance == null)
    instance = new DatabaseImporter();

    return DatabaseImporter.instance;
    }

    private DatabaseImporter (){

    }

    public void importDatabaseFromFile(Context context, String databaseName , String filePath){

    SQLiteDatabase database = //CREATE UR DATABASE WITH THE COMMAND FROM THE DATABASE API YOUR USING

    this.executeSqlCommands( database ,
    this.readSqlCommandsFromFile(filePath)
    );
    }

    private String[] readSqlCommandsFromFile(String filePath){

    String[] sqlCommands = new String[0];
    List<String> sqlCommandsList = new LinkedList<String>();

    try{

    // Open the file that is the first
    // command line parameter
    FileInputStream fstream = new FileInputStream(filePath);
    BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine()) != null) {
    if(!strLine.equals("") && !strLine.equals(" ") && strLine != null)
    sqlCommandsList.add(strLine);
    }
    //Close the input stream
    in.close();

    }catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());
    }

    sqlCommands = new String[sqlCommandsList.size()];

    sqlCommandsList.toArray(sqlCommands);

    return sqlCommands;
    }

    private void executeSqlCommands(SQLiteDatabase database, String[] sqlCommands){

    for(int i = 0; i < sqlCommands.length ; i++){

    database.execSQL(sqlCommands[i]);
    }
    }

    }

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

Sidebar

Related Questions

Is there any way to access the iPhone/iPod touch settings programatically ? Thanks. Biranchi
Is there a way to programatically stop the phone from sleeping? Since my game
Is there any way to programatically compare two sound files to determine if they
Is there a way to recall import/export utilities of SQL Server programmatically. In my
Is there a way to programatically add TextView and show it right next to
Is there a way to programatically track the size of a particular session on
Is there any way to (programatically) find out what your app's name is? I'm
Is there any way to programatically access, through the Twitter API or otherwise, the
As per the title, is there any way to programatically change the selected item
I have some VirtualBox VMs running. Is there any way to programatically get the

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.