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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:15:14+00:00 2026-05-27T09:15:14+00:00

I am coding an application that connects to a localhost. When the application first

  • 0

I am coding an application that connects to a localhost. When the application first runs I want it to initialize the Database using this method:

public void initDataBase() {
    try {
        Statement stm = con.createStatement();
        stm.executeQuery("source shippingSQLscript.sql");
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
}

Where shippingSQLscript.sql contains the correct sql statements to insert all the data. However when I run it the method throws:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
You have an error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near 'source shippingSQLscript.sql'
at line 1

I have tried using stm.execute() as well but have had the same result.

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

    You cannot do this with the JDBC driver. source is only a command supported by the MySQL command line tool. See here:

    http://forums.mysql.com/read.php?39,406094,406329#msg-406329

    Here’s the list of commands for the command-line tool. Most are not supported as JDBC query statements.

    http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html

    You will have to load your SQL commands from the file in your code and send them to JDBC execute methods. Something like:

    Statement stm = con.createStatement();
    BufferedReader reader = new BufferedReader(new FileReader(new File(...)));
    while (true) {
        String line = reader.readLine();
        if (line == null) {
            break;
        }
        // this is the trick -- you need to pass different SQL to different methods
        if (line.startsWith("SELECT")) {
            stm.executeQuery(line);
        } else if (line.startsWith("UPDATE") || line.startsWith("INSERT")
            || line.startsWith("DELETE")) {
            stm.executeUpdate(line);
        } else {
            stm.execute(line);
        }
    }
    stm.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writting an application in C# that connects to a database that is used
I'm coding an application that needs to select an area of the screen. I
assume that i start coding an application from scratch, is the best way to
I want to create a WinForm application that must draw data coming from a
I’m coding an application with server resources in mind, so I don’t want to
I'm coding the menu for an application I'm writing in python, using wxPython libraries
I'm writing a XUL application using JavaScript for the coding. I would like to
Hii I was coding for an application that shows the list of running process
I want to test a application that is hosted on skytap inside a windows
I'm coding a web application in GWT. I have a class that handles all

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.