jdbc应用程序更新sql对我不起作用,任何想法

时间:2018-08-20 14:14:44

标签: java mysql jdbc

public void Update(String name, String mobile, String email, String car, String model, String year, String color, String plate_no, String plateletters,String gear, String km, String date,String licesnse,String status, String notes){
    Connection conn = null;
    try{
        conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
        System.out.println("connected");
        Statement stmt = (Statement) conn.createStatement();
        String ins = "update car"
                + "set Name = '"+name+"' , "
                + "Email = '"+email+"' , "
                + "Car = '"+car+"' , "
                + "Model = '"+model+"' , "
                + "Year = '"+year+"' , "
                + "Color = '"+color+"' , "
                + "Plateno = '"+plate_no+"' , "
                + "Plateletters = '"+plateletters+"' , "
                + "Gearbox = '"+gear+"' , "
                + "Km = '"+km+"' , "
                + "Date = '"+date+"' , "
                + "License = '"+licesnse+"' , "
                + "Status = '"+status+"' , "
                + "Notes = '"+notes+"'  "
                + "where Mobile = '"+mobile+"' ";

        stmt.execute(ins);

    }catch(SQLException e){
        JOptionPane.showMessageDialog(null, e.getMessage());
        System.err.println(e);
        return;
    }

}

**我已经尝试过准备好的陈述和stmt.executeUpdate(ins);,但没有任何效果!

请帮助!**

错误:

  

java.sql.SQLSyntaxErrorException:SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以在第1行的'='ahmed',Email ='ahmed@hotmail.com',Car ='honda',Model ='hondaz',是的附近使用正确的语法

2 个答案:

答案 0 :(得分:1)

使用 import React, { Component } from 'react'; import Dropzone from 'react-dropzone'; class Accept extends React.Component { constructor() { super() this.state = { accepted: [], rejected: [] } } render() { var azure = require('azure-storage'); var auzre_storage_account = 'testuploadcontainer'; var azure_storage_access_key = 'ACCESS_KEY' var containerName = "testuploadcontainer" var blobService = azure.createBlobService(auzre_storage_account, azure_storage_access_key); return ( <section> <div className="audiodropzone"> <Dropzone className="audiodropzonetext" accept="video/*" onDrop={(accepted, rejected) => { var blobUrl = accepted[0].preview; var xhr = new XMLHttpRequest(); xhr.open("GET", blobUrl); xhr.responseType = "text"; xhr.onload = function () { const Stream = require('stream'); const readable = new Stream.Readable() readable.push(xhr.responseText); readable.push(null); blobService.createBlockBlobFromStream(containerName, accepted[0].name, readable, xhr.responseText.length, (error, result, response) => { var ok = 0; }) } xhr.send(); this.setState({ accepted, rejected }); }} > <center><b>Try dropping some files here, or click to select files to upload.</b></center> <center><i>Only audio files (mp4, avi, mp3 and wmv) will be accepted</i></center> </Dropzone> </div> <aside> <div className="row"> <div className="col-sm-6"> <h2>Accepted files</h2> <ul> { this.state.accepted.map(f => <li key={f.name}>{f.name} - {f.size} bytes</li>) } </ul> </div> <div className="col-sm-6"> <h2>Rejected files</h2> <ul> { this.state.rejected.map(f => <li key={f.name}>{f.name} - {f.size} bytes</li>) } </ul> </div> </div> </aside> </section> ); } } <Accept /> export default Accept; 的{​​{1}}。

preparedStatement

答案 1 :(得分:1)

您需要确保在SQL查询的元素之间添加适当的空间:

 String ins = "update car"

应该是

 String ins = "update car "

一种好的方法是在数据库查询工具(SQL开发人员,phpMyAdmin等)中编写和执行SQL,并在尝试用Java重写之前确保语法正确。