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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:41:28+00:00 2026-06-01T20:41:28+00:00

How do you preform this type of action using jdbc? String x = (\\.

  • 0

How do you preform this type of action using jdbc?

String x = ("\\. /home/user/Desktop/dbfile.sql");

Class.forName(Database.JDBC_DRIVER);
Connection conn = (Connection) DriverManager.getConnection(
    Database.DB_URL + "localhost" + "/" + "mydatabase", "root", "");
Statement stmt = (Statement) conn.createStatement();

stmt.execute(x);

Results: Exception in thread “main” 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 ‘.

I’ve tried this

public static void main(String[] args) throws Exception
  {

    String x = readFileAsString("/home/user/Desktop/myDB.sql");

    Class.forName(Database.JDBC_DRIVER);
    Connection conn = (Connection) DriverManager.getConnection(
        Database.DB_URL + "localhost" + "/" + "mydb", "root", "");
    Statement stmt = (Statement) conn.createStatement();

    System.out.println(x);
    stmt.execute(x);

  }

  private static String readFileAsString(String filePath) throws Exception
  {
    byte[] buffer = new byte[(int) new File(filePath).length()];
    BufferedInputStream f = null;
    try
    {
      f = new BufferedInputStream(new FileInputStream(filePath));
      f.read(buffer);
    }
    finally
    {
      if (f != null)
        try
        {
          f.close();
        }
        catch (IOException ignored)
        {
        }
    }
    return new String(buffer);
  }

Result

Exception in thread "main" 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 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

My file looks like

-- MySQL dump 10.13  Distrib 5.5.21, for Linux (x86_64)
--
-- Host: localhost    Database: DOG
-- ------------------------------------------------------
-- Server version   5.5.21

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `DOG`
--

DROP TABLE IF EXISTS `DOG`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `DOG` (
  `DOG_ID` mediumint(9) NOT NULL,
  `OWNER_ID` mediumint(9) NOT NULL,
  PRIMARY KEY (`DOG_ID`,`OWNER_ID`),
  KEY `CHANNEL_FK1` (`OWN_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
  • 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-01T20:41:30+00:00Added an answer on June 1, 2026 at 8:41 pm

    You can’t do that. You will need to open dbfile.sql yourself, and run all the lines though JDBC API.

    Provided you have ONE SQL SENTENCE PER LINE this might work:

    Class.forName(Database.JDBC_DRIVER);
    Connection conn = (Connection) DriverManager.getConnection(
        Database.DB_URL + "localhost" + "/" + "mydatabase", "root", "");
    Statement stmt = (Statement) conn.createStatement();
    BufferedReader reader = new BufferedReader( new FileReader ("/home/user/Desktop/dbfile.sql"));
    String line  = null;
    while( ( line = reader.readLine() ) != null ) {
        stmt.executeUpdate(line);    
    }
    stmt.close();
    conn.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I am using a class to bring back items from a database, say
I am using cakephp and creating a form <?php echo $form->create('User', array('action' => 'cancel'));?>
This piece of code is supposed to go through a list and preform some
I find myself using this method a ton to perform actions based on a
I'm having more problem with JSON! I am using the advice from this article
I am trying to query this very complicated XML document using xDocument and LINQ
Is it possible use a MySQL query to perform this kind of check? If
After creating a new form, I usually perform this ritual: Change the name into
With a classic method implementation, I usually perform BeginInvoke like this: private delegate void
I would like to perform something similar to this (ie get the sum of

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.