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

  • Home
  • SEARCH
  • 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 6723615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:35:24+00:00 2026-05-26T09:35:24+00:00

I want to create database import using .sql file with java then I found

  • 0

I want to create database import using .sql file with java then I found a code something like this

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(new String[]{"/bin/bash","-c","mysql -p -h localhost test < "+fileName.toString()});

I’m using netbean to run my desktop app. then I got this error message

java.io.IOException: Cannot run program "/bin/bash": CreateProcess error=2, The system cannot find the file specified

my question is where can i find /bin/bash path? or what should i do…
should I configure something like env variable path?

I’m running this on windows

solution is replacing /bin/bash with cmd.exe and -c to /c, but when I execute the program I got this message appear on my console

‘mysql’ is not recognized as an internal or external command,
operable program or batch file.

though I already setup mysql directory in PATH environment variable of Windows

  • 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-26T09:35:25+00:00Added an answer on May 26, 2026 at 9:35 am

    /bin/bash doesn’t exist on Windows. Try replacing /bin/bash with cmd.exe, and replacing the switch -c with /c.

    EDIT: if your Java program appears to complete successfully but no data has been written, it is quite possible that your Java program didn’t wait for the mysql process to complete. Try adding pr.waitFor();.

    Alternatively, mysql could be reporting an error message or writing something to its standard output or standard error streams. If this is the case, you’ll need to either:

    1. read the offending stream(s), or
    2. if you’re sure you can ignore it, redirect the offending stream(s) to NUL.

    You can redirect standard output to NUL by adding >NUL to the command line, and redirect standard error to NUL by adding 2>NUL.

    I woudn’t recommend discarding the output/error messages. If there’s an error, how will you know about it? However, it’s difficult to properly handle the standard output and standard error streams of processes generated using Runtime.getRuntime().exec(...). Instead, I would use a ProcessBuilder. A ProcessBuilder allows you to redirect the mysql process’s standard error into the standard output, which makes reading the output from both streams a bit easier (you don’t need two separate threads).

    ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", "mysql -p -h localhost test < "+fileName.toString());
    builder.redirectErrorStream(true);
    Process pr = builder.start();
    
    // Get mysql process's standard output/error.
    InputStream is = pr.getInputStream();
    
    // Now read from it and write it to standard output.
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    String line = reader.readLine();
    while (line != null) {
        System.out.println(line);
        line = reader.readLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to insert data in MYSQL database using python here my code import
I want to create a SQL Server Express database on my local machine and
i want to create tabs according to data from MySQL database using php for
I am creating database at runtime and I want to create the tables in
I'm using SQL Server 2005. I've created a snapshot of database (RM_DB), I want
I have a .sql file and I want to load it into MySQL database.
Say I want to create a database using the Android SDK's sqlite tool. What
I want my code to automatically try multiple ways to create a database connection.
I create a table in database using sqlalchemy and now want to make a
I want to create a large database of GPS coordinates that can be queried

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.