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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:51:41+00:00 2026-06-18T02:51:41+00:00

Please find the error in this code , I am trying to save the

  • 0

Please find the error in this code , I am trying to save the data but it’s not storing
using Eclipse , MySQL , 64 bit

Error :

java.sql.SQLException: [MySQL][ODBC 5.2(w) Driver][mysqld-5.5.28]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 ‘database
(‘did’,’dname’,’dadress’,’salary’,’sex’,’specialist’,’cell#’)VALUES
(?,’ at line 1

package pk.pucit;
import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

class DoctorsRecord {

public JFrame frm=new JFrame("Doctor's Record Information");
public  JButton btn1,btn2,btn3,btn4;
public  JLabel lbl1,lbl2,lbl3,lbl4,lbl5,lbl6,lblr;
public JTextField txt1,txt2,txt3,txt4,txt5,txt6,txt7;
public  JRadioButton rbtn1,rbtn2;
//frm.setBackground(Color.green);

public DoctorsRecord(){
    lbl1=new JLabel("Doctor ID");
    lbl2=new JLabel("Doctor's Name");
    lbl3=new JLabel("Address");
    lblr=new JLabel("Gender");
    lbl4=new JLabel("Salary");
    lbl5=new JLabel("Rank");
    lbl6=new JLabel("Ph #");


    txt1=new JTextField(7);
    txt2=new JTextField(7);
    txt3=new JTextField(7);
    txt4=new JTextField(7);
    txt5=new JTextField(7);
    txt6=new JTextField(7);
    txt7=new JTextField(7);

    /*rbtn1=new JRadioButton("Male");
    rbtn2=new JRadioButton("Female");*/

    btn1=new JButton("Save");
    btn2=new JButton("Search ");
    btn3=new JButton("Reset");
    btn4=new JButton("Cancel");

    JPanel pnl1=new JPanel();

    pnl1.add(lbl1);
    pnl1.add(txt1);
    pnl1.add(lbl2);
    pnl1.add(txt2);
    pnl1.add(lbl3);
    pnl1.add(txt3);
    pnl1.add(lblr);
    pnl1.add(txt7);
    pnl1.add(lbl4);
    pnl1.add(txt4);
    pnl1.add(lbl5);
    pnl1.add(txt5);
    pnl1.add(lbl6);
    pnl1.add(txt6);
    pnl1.setLayout(new GridLayout(8,1));

    JPanel pnl=new JPanel();

    pnl.add(btn1);
    pnl.add(btn2);
    pnl.add(btn3);
    pnl.add(btn4);
    pnl.setLayout(new GridLayout(1,2));

    frm.add(pnl1,BorderLayout.CENTER);
    frm.add(pnl,BorderLayout.SOUTH);

    //frm.setLayout(new GridLayout(10,1));
    frm.setBounds(400,100,400,500);
    frm.setVisible(true);
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    btn1.addActionListener(new ActionListener()
    {

        public void actionPerformed(ActionEvent ae){
            try{
                String id=txt1.getText();
                String name=txt2.getText();
                String add=txt3.getText();
                String sal=txt4.getText();
                String sex=txt5.getText();
                String sep=txt6.getText();
                String cell=txt7.getText();
                dataHandler(id,name,add,sal,sex,sep,cell);
            }
            catch(Exception e){
                System.out.println("Exception occur");
            }
        } 

    }
            );
}
    public void dataHandler(String id,String dn,String add,String sal,String   sex,String sep,String cell)throws ClassNotFoundException, SQLException{
        try{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:Dbms", "root", "root");
    String query = "insert into database    ('did','dname','dadress','salary','sex','specialist','cell#')" +"VALUES (?,?,?,?,?,?,?)";
       PreparedStatement preparedStatement = con.prepareStatement(query);
        preparedStatement.setString(1, id);
        preparedStatement.setString(2, dn);
        preparedStatement.setString(3, add);
        preparedStatement.setString(4, sal);
        preparedStatement.setString(5, sex);
        preparedStatement.setString(6, sep);
        preparedStatement.setString(7, cell);
        preparedStatement.execute();
        con.close();
    }catch(Exception oc){
        System.out.println(oc.toString());
    }
    }
    public static void main(String []args){
        new DoctorsRecord();

    }
}
  • 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-18T02:51:42+00:00Added an answer on June 18, 2026 at 2:51 am

    There are two problems with you query.

    First, DataBase is a Reserved Keyword, you must escape it with backtick.

    String query = "insert into `database` (did,dname,dadress,salary,sex,specialist,`cell#`) 
                    VALUES (?,?,?,?,?,?,?)";
    

    Second, the column names must not be wrap with single quotes. because if you do that, it will also generate an error telling you that the column was not found. Only columnNames and tableNames can be enclosed with backtick.

    • MySQL Reserved Keywords
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run this code, it shows error. Please, help me out. I'm trying
Im trying to create sun, but when I test run this code I get
I'm trying to save some inputs from a form into my MySQL database, but
I was just trying the below code and it is not working.. please suggest
Please help me to find out error in my SQL query. I have created
Please find the below code <?xml version=1.0 encoding=utf-8?> <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml layout=absolute> <mx:Script> <![CDATA[ [Bindable]
Please find the code at http://jsfiddle.net/wlogeshwaran/NGL8P/4/ Here i want to make the 'hi' ,
I am using readDirSync to get the files from a Diretory. PLease find the
Please look at this picture: Is it possible to find per-column sum for all
Please help me, I'm trying to find some documentation about pre-installed applications at Android.

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.