插入数据时出现问题

发布于 2024-10-31 14:59:26 字数 6585 浏览 1 评论 0原文

当我保存数据时,出现以下错误:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in date in query expression '#444434'

在插入数据时,我将此日期设为 4.4.4434

我的代码是:

int len, len1, len2;  
int regno = Integer.parseInt(cbregn.getSelectedItem().toString());
if (cbregn.getSelectedItem().toString().equals("")) {
   JOptionPane.showMessageDialog(null," SELECT THE REGISTRATION NO ");
   return;
}

String dt = tdate.getText();
dt = dt.replace(".", "");
Integer.parseInt(dt);
if (dt.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE DATE ");
    return;
}

//string number = "4.5.5255";
//number = number.replace(".", "");
//Integer.parseInt(number );
// int dt = Integer.parseInt(tdate.getText());
// if (tdate.getText().equals(""))
//     JOptionPane.showMessageDialog(null," ENTER THE DATE ");
// String date=tdate.getText();
// if (dt.equals("")) {
//     JOptionPane.showMessageDialog(null," ENTER THE DATE ");
//     return;
// }


String nm = cbnm.getSelectedItem().toString();
if (nm.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE NAME ");
    return;
}

String place=tfplace.getText();
if (place.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE NATIVE PLACE ");
    return;
}

String kul = tfkul.getText();
if (kul.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE NAME OF KUL ");
    return;
}

String gotra = tfgotra.getText();
if(gotra.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE GOTRA NAME ");
    return;
}

String kswami = tfswami.getText();
if (kswami.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE KULSWAMI NAME ");
    return;
}

String raddr = taraddr.getText();
if (raddr.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE RESIDENTIAL ADDRESS ");
    return;
}

    int pincode=Integer.parseInt(tfpcd.getText());
    len1 = tfpcd.getText().length();
    if(len1!=7) {
    JOptionPane.showMessageDialog(null,"Enter The 7 Digit Pin Code","Error",JOptionPane.ERROR_MESSAGE);
    return;
    }

    int stdcd=Integer.parseInt(tfstdcode.getText());
    if(tfstdcode.getText().equals("")){
    JOptionPane.showMessageDialog(null," ENTER THE STD CODE ");
    return;
    }


    int tele=Integer.parseInt(tftele.getText());
    len2 = tftele.getText().length();
    if(len2!=7){
    JOptionPane.showMessageDialog(null,"Enter The 7 Digit Telephone No","Error",JOptionPane.ERROR_MESSAGE);
    return;
    }


    int mno=(int) Long.parseLong(tfmno.getText());
    len = tfmno.getText().length();
    if(len!=10) {
    JOptionPane.showMessageDialog(null,"Enter The 10 Digit Mobile No","Error",JOptionPane.ERROR_MESSAGE);
    return;
    }


    String email=tfemail.getText();
    if(email.equals(""))
    JOptionPane.showMessageDialog(null," ENTER THE EMAIL");

    if(email.equals("")) {
        tfemail.setText("-");

    } else // check if it is a valid email-id
    {
    int ind = email.indexOf("@");
        if (ind != -1) { } else {
            JOptionPane.showMessageDialog(null,"Invalid Email Id","Error",JOptionPane.ERROR_MESSAGE);
            tfemail.setText("");
            tfemail.requestFocus();
            return;
        }
    }
    String website=tfweb.getText();
    if(website.equals(""))
    JOptionPane.showMessageDialog(null," ENTER THE WEBSITE ");

    if(website.equals("")) {
        tfweb.setText("-");
    }
    else // check if it is a valid email-id
    {
    int ind = website.indexOf("www");
    if (ind != -1) { } else {
    JOptionPane.showMessageDialog(null,"Invalid Website","Error",JOptionPane.ERROR_MESSAGE);
    tfweb.setText("");
    tfweb.requestFocus();
    return;
   }
}

    String education=tfedu.getText();
    if(education.equals("")){
    JOptionPane.showMessageDialog(null," ENTER THE EDUCATION DETAILS");
    return;
   }

    String branch=tfbrch.getText();
    if(branch.equals("")){
    JOptionPane.showMessageDialog(null," ENTER THE BRANCH NAME ");
    return;
   }

String bdt = tfbdt.getText();
bdt = bdt.replace(".", "");
Integer.parseInt(bdt);
//      int bdt=Integer.parseInt(tfbdt.getText());
//      if(tfbdt.getText().equals(""))
//      String brthdt=tfbdt.getText();
  if(bdt.equals("")){
  JOptionPane.showMessageDialog(null," ENTER THE BIRTH DATE");
  return;
  }


    String bloodgrp=(String)cbbldgrp.getSelectedItem();
    if(bloodgrp.equals("")){
    JOptionPane.showMessageDialog(null," SELECT THE BLOODGROUP");
    return;
   }

    try
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
       Statement stmt=con.createStatement();

        String qry= "INSERT INTO Registration1(RegistrationNo,SeniorPerson,NativePlace,Kul,Gotra,KulSwami,ResidensialAddress,PinCode,STDcode,TelephoneNo,MobileNo,Email,Website,Education,Branch,BloodGroup,[Date],BirthDate) VALUES('"+regno+"','"+nm+"','"+place+"','"+kul+"','"+gotra+"','"+kswami+"','"+raddr+"','"+pincode+"','"+stdcd+"','"+tele+"','"+mno+"','"+email+"','"+website+"','"+education+"','"+branch+"','"+bloodgrp+"',#"+dt+"#,#"+bdt+"#)";
        stmt.executeUpdate(qry);
//            PreparedStatement pstmt = con.prepareStatement ("INSERT INTO Registration1 (RegistrationNo,Date,SeniorPerson,NativePlace,Kul,Gotra,KulSwami,ResidensialAddress,PinCode,STDcode,TelephoneNo,MobileNo,Email,Website,Education,Branch,BirthDate,BloodGroup) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
//            pstmt.setInt(1, regno);
//            pstmt.setString(2, dt);
//            pstmt.setString(3, nm);
//            pstmt.setString(4, place);
//            pstmt.setString(5, kul);
//            pstmt.setString(6, gotra);
//            pstmt.setString(7, kswami);
//            pstmt.setString(8, raddr);
//            pstmt.setInt(9, pincode);
//            pstmt.setInt(10, stdcd);
//            pstmt.setInt(11, tele);
//            pstmt.setInt(12, mno);
//            pstmt.setString(13, email);
//            pstmt.setString(14, website);
//            pstmt.setString(15, education);
//            pstmt.setString(16, branch);
//            pstmt.setString(17, bdt);
//            pstmt.setString(18, bloodgrp);
//            pstmt.executeUpdate();
        JOptionPane.showMessageDialog(null,"RECORD IS SAVED SUCCESSFULLY ");
        con.close();

    }
    catch(SQLException eM) {
        System.out.println(" "+eM);
        JOptionPane.showMessageDialog(null,"RECORD IS NOT SAVED");
    } 
    catch(Exception et)
    {
        System.out.println("error:"+et.getMessage());
    }

when i am saving the data it is giving the error below:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in date in query expression '#444434'

while inserting the data i have taken this date as 4.4.4434

my code is:

int len, len1, len2;  
int regno = Integer.parseInt(cbregn.getSelectedItem().toString());
if (cbregn.getSelectedItem().toString().equals("")) {
   JOptionPane.showMessageDialog(null," SELECT THE REGISTRATION NO ");
   return;
}

String dt = tdate.getText();
dt = dt.replace(".", "");
Integer.parseInt(dt);
if (dt.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE DATE ");
    return;
}

//string number = "4.5.5255";
//number = number.replace(".", "");
//Integer.parseInt(number );
// int dt = Integer.parseInt(tdate.getText());
// if (tdate.getText().equals(""))
//     JOptionPane.showMessageDialog(null," ENTER THE DATE ");
// String date=tdate.getText();
// if (dt.equals("")) {
//     JOptionPane.showMessageDialog(null," ENTER THE DATE ");
//     return;
// }


String nm = cbnm.getSelectedItem().toString();
if (nm.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE NAME ");
    return;
}

String place=tfplace.getText();
if (place.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE NATIVE PLACE ");
    return;
}

String kul = tfkul.getText();
if (kul.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE NAME OF KUL ");
    return;
}

String gotra = tfgotra.getText();
if(gotra.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE GOTRA NAME ");
    return;
}

String kswami = tfswami.getText();
if (kswami.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE KULSWAMI NAME ");
    return;
}

String raddr = taraddr.getText();
if (raddr.equals("")) {
    JOptionPane.showMessageDialog(null," ENTER THE RESIDENTIAL ADDRESS ");
    return;
}

    int pincode=Integer.parseInt(tfpcd.getText());
    len1 = tfpcd.getText().length();
    if(len1!=7) {
    JOptionPane.showMessageDialog(null,"Enter The 7 Digit Pin Code","Error",JOptionPane.ERROR_MESSAGE);
    return;
    }

    int stdcd=Integer.parseInt(tfstdcode.getText());
    if(tfstdcode.getText().equals("")){
    JOptionPane.showMessageDialog(null," ENTER THE STD CODE ");
    return;
    }


    int tele=Integer.parseInt(tftele.getText());
    len2 = tftele.getText().length();
    if(len2!=7){
    JOptionPane.showMessageDialog(null,"Enter The 7 Digit Telephone No","Error",JOptionPane.ERROR_MESSAGE);
    return;
    }


    int mno=(int) Long.parseLong(tfmno.getText());
    len = tfmno.getText().length();
    if(len!=10) {
    JOptionPane.showMessageDialog(null,"Enter The 10 Digit Mobile No","Error",JOptionPane.ERROR_MESSAGE);
    return;
    }


    String email=tfemail.getText();
    if(email.equals(""))
    JOptionPane.showMessageDialog(null," ENTER THE EMAIL");

    if(email.equals("")) {
        tfemail.setText("-");

    } else // check if it is a valid email-id
    {
    int ind = email.indexOf("@");
        if (ind != -1) { } else {
            JOptionPane.showMessageDialog(null,"Invalid Email Id","Error",JOptionPane.ERROR_MESSAGE);
            tfemail.setText("");
            tfemail.requestFocus();
            return;
        }
    }
    String website=tfweb.getText();
    if(website.equals(""))
    JOptionPane.showMessageDialog(null," ENTER THE WEBSITE ");

    if(website.equals("")) {
        tfweb.setText("-");
    }
    else // check if it is a valid email-id
    {
    int ind = website.indexOf("www");
    if (ind != -1) { } else {
    JOptionPane.showMessageDialog(null,"Invalid Website","Error",JOptionPane.ERROR_MESSAGE);
    tfweb.setText("");
    tfweb.requestFocus();
    return;
   }
}

    String education=tfedu.getText();
    if(education.equals("")){
    JOptionPane.showMessageDialog(null," ENTER THE EDUCATION DETAILS");
    return;
   }

    String branch=tfbrch.getText();
    if(branch.equals("")){
    JOptionPane.showMessageDialog(null," ENTER THE BRANCH NAME ");
    return;
   }

String bdt = tfbdt.getText();
bdt = bdt.replace(".", "");
Integer.parseInt(bdt);
//      int bdt=Integer.parseInt(tfbdt.getText());
//      if(tfbdt.getText().equals(""))
//      String brthdt=tfbdt.getText();
  if(bdt.equals("")){
  JOptionPane.showMessageDialog(null," ENTER THE BIRTH DATE");
  return;
  }


    String bloodgrp=(String)cbbldgrp.getSelectedItem();
    if(bloodgrp.equals("")){
    JOptionPane.showMessageDialog(null," SELECT THE BLOODGROUP");
    return;
   }

    try
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");
       Statement stmt=con.createStatement();

        String qry= "INSERT INTO Registration1(RegistrationNo,SeniorPerson,NativePlace,Kul,Gotra,KulSwami,ResidensialAddress,PinCode,STDcode,TelephoneNo,MobileNo,Email,Website,Education,Branch,BloodGroup,[Date],BirthDate) VALUES('"+regno+"','"+nm+"','"+place+"','"+kul+"','"+gotra+"','"+kswami+"','"+raddr+"','"+pincode+"','"+stdcd+"','"+tele+"','"+mno+"','"+email+"','"+website+"','"+education+"','"+branch+"','"+bloodgrp+"',#"+dt+"#,#"+bdt+"#)";
        stmt.executeUpdate(qry);
//            PreparedStatement pstmt = con.prepareStatement ("INSERT INTO Registration1 (RegistrationNo,Date,SeniorPerson,NativePlace,Kul,Gotra,KulSwami,ResidensialAddress,PinCode,STDcode,TelephoneNo,MobileNo,Email,Website,Education,Branch,BirthDate,BloodGroup) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
//            pstmt.setInt(1, regno);
//            pstmt.setString(2, dt);
//            pstmt.setString(3, nm);
//            pstmt.setString(4, place);
//            pstmt.setString(5, kul);
//            pstmt.setString(6, gotra);
//            pstmt.setString(7, kswami);
//            pstmt.setString(8, raddr);
//            pstmt.setInt(9, pincode);
//            pstmt.setInt(10, stdcd);
//            pstmt.setInt(11, tele);
//            pstmt.setInt(12, mno);
//            pstmt.setString(13, email);
//            pstmt.setString(14, website);
//            pstmt.setString(15, education);
//            pstmt.setString(16, branch);
//            pstmt.setString(17, bdt);
//            pstmt.setString(18, bloodgrp);
//            pstmt.executeUpdate();
        JOptionPane.showMessageDialog(null,"RECORD IS SAVED SUCCESSFULLY ");
        con.close();

    }
    catch(SQLException eM) {
        System.out.println(" "+eM);
        JOptionPane.showMessageDialog(null,"RECORD IS NOT SAVED");
    } 
    catch(Exception et)
    {
        System.out.println("error:"+et.getMessage());
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尘曦 2024-11-07 14:59:26

是什么让您认为插入日期的正确格式是“#444434#”?我对 odbc 连接访问一无所知,但这不是我见过的 sql 日期语法。您应该:

  1. 使用 jdbc 日期转义语法
  2. 使用以下之一PreparedStatement 的日期/时间特定方法
  3. 或找出访问 odbc 连接的正确日期语法

what makes you think that the correct format for inserting the date is "#444434#"? i don't know anything about the odbc connection for access, but that is not a sql date syntax i've ever seen. you should:

  1. use the jdbc date escape syntax
  2. use one of the date/time specific methods of a PreparedStatement
  3. or figure out the correct date syntax for the access odbc connection
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文