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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:25:41+00:00 2026-06-08T23:25:41+00:00

Given this code : package db; import java.io.*; import java.sql.*; public class Connect {

  • 0

Given this code :

package db;
import java.io.*;
import java.sql.*;


public class Connect 
{


    // creating a table for each type person in the bank 

    public void createTable(Statement state,String tableType) throws SQLException
    {
        state.executeUpdate (

                "CREATE TABLE IF NOT EXISTS "+ tableType +" ("
                + "FirstName CHAR(20), LastName CHAR(20),"
                + "Address CHAR(50), PhoneNumber CHAR(20),"
                + "UserName CHAR(20), Password CHAR(20))");
    }



    public void insertDataToTable(Statement statement , String table 
            ,String firstName,String lastName,String address, String phoneNumber , String userName, String password)
    {
        try
        {
            statement.executeUpdate("INSERT INTO table (`FirstName` ,`LastName` , `Address` , `PhoneNumber` , `UserName` , `Password`) " +
                    "values ( '"+firstName+"','"+lastName+ "','"+address+"','"+phoneNumber+"','"+userName+ "'," +password+")");



        }

        catch(Exception e)
        {
            System.out.println(e.toString());
        }

    }


    public void start()
    {

        System.out.println("Database creation example!");
        Connection con = null;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost","root","root");
            try
            {

                Statement st = con.createStatement();

                // create a database 

                st.executeUpdate("CREATE DATABASE IF NOT EXISTS Personnel"); 
                st.executeUpdate("USE Personnel");

                // create tables

                //Create a table for each user type!
                createTable(st, "ClientsTable");
                createTable(st, "ClerksTable");
                createTable(st, "ManagersTable");
                createTable(st, "AdminsTable");

                this.insertDataToTable(st, "ClientsTable", "my", "name", "is", "erl", "I", "think");

                ResultSet rs = st.executeQuery("SELECT `FirstName` FROM `ClientsTable`");
                while (rs.next() == true)
                { 
                    System.out.println(rs.getString("FirstName")); 
                }



            } // end try  

            catch (SQLException s)
            {
                System.out.println("SQL statement is not executed!");
            }


        } // end try 



        catch (Exception e){
            e.printStackTrace();
        }


    }  // end start



}

When I execute from my Main :

package db;

public class Main {

    public static void main(String [ ] args)
    {

        Connect myConnection = new Connect();

        myConnection.start();
    }

}

And reach that line in start() method :

this.insertDataToTable(st, "ClientsTable", "my", "name", "is", "erl", "I", "think");

I get the following output from the server (using the try/catch) :

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 'table (`FirstName` ,`LastName` , `Address` , `PhoneNumber` , `UserName` , `Passw' at line 1

I checked the manual but I can’t seem to find the source of the problem . Any idea what’s wrong here ? thanks

  • 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-08T23:25:42+00:00Added an answer on June 8, 2026 at 11:25 pm

    Your table name is a variable I believe. However you have used the String “table” directly. But this isn’t an issue.

    Your password variable value requires a single quote.

    "values ( '"+firstName+"','"+lastName+ "','"+address+"','"+phoneNumber+"','"+userName+ "','" +password+"')");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this code : package db; import java.sql.*; public class Main { public static
Source Code of LoginAction.java package com.test; import java.util.ArrayList; import java.util.List; public class LoginAction {
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:
Given the following not-very-useful code: package com.something; import java.util.ArrayList; import java.util.Collection; //Not a generic
Given this code: List<Integer> ints = new ArrayList<Integer>(); // Type mismatch: // cannot convert
I am brand new to Java and was given this piece of code, no
Given this code, tableButton = new JButton(new ImageIcon(80F_FG2015.GIF)); how would I get that String
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
Given this code: List<string> things = new List<string>(); foreach (string thing in things) {
So I was given this code in a folder of bits and pieces that

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.