当前位置: 首页 > 知识库问答 >
问题:

使用springMVC将文件夹上载到mysql时出错

柳飞鸾
2023-03-14

我正在构建一个应用程序。用户将查看一个页面,用户应该输入患者代码,以及以下描述,然后,用户将上传包含CSV文件的文件夹。我正在尝试使用spring MVC - JSP上传“一个包含CSV文件的文件夹”(不是zip/rar文件)

这是我的JSP代码:

<div class="w3-row w3-section">
                        <div class="w3-col" style="width:200px">* Patient code</div>
                        <div class="w3-rest">
                            <%--<form:select path="patient">--%>
                                <%--<form:options items="${patient}" itemLabel="name" itemValue="id"/>--%>
                            <%--</form:select>--%>
                                <form:input type="text" path="id_patient" name="id_patient" id="id_patient" placeholder="input number 1-20" class="w3-input w3-border"/>
                        </div>
                    </div>

                    <div class="w3-row w3-section">
                        <div class="w3-col" style="width:200px">* Patient description</div>
                        <div class="w3-rest">
                            <form:input type="text" path="description" name="description" id="description" placeholder="put any description" class="w3-input w3-border"/>
                        </div>
                    </div>

                    <div class="w3-row w3-section">
                        <div class="w3-col" style="width:200px">* Input Data Files</div>
                        <div class="w3-rest">
                            <input type="file" path="fileName" name="attachFileObj" webkitdirectory directory />
                        </div>
                    </div>

这是我的患者.java文件:

public class Patient {

    //field patient
    private int id_patient;
    private String description;
    private String patient;


    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getId_patient() {
        return id_patient;
    }

    public void setId_patient(int id_patient) {
        this.id_patient = id_patient;
    }

    public String getPatient() {
        return patient;
    }

}

这是我的附件.java类:

package com.Patient.pojo;

public class Attachment {
    //field attachment
    private int id_data;
    private byte[] data;
    private String fileName;
    private int patientID;

    public int getId_data() {
        return id_data;
    }

    public void setId_data(int id_data) {
        this.id_data = id_data;
    }

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }

    public int getPatientID() {
        return patientID;
    }

    public void setPatientID(int patientID) {
        this.patientID = patientID;
    }
}

这是我的dao文件:

@Override
    public void saveAttachment(Patient patient, Attachment attachment) {

        if(null != jdbcTemplate) {
            // Performing The Sql 'Insert' Operation
            String sql = "insert into patient(id_patient, description) values(?,?);" +
                    "insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));";


            jdbcTemplate.update(sql, patient.getDescription(), attachment.getId_data(), attachment.getData(), attachment.getPatientID());

//            int insertCount = jdbcTemplate.update(sql, patient.getData());
//            if(insertCount == 1) {
//                System.out.println("The Uploaded File Is Successfully Saved In The Database...!" + "\n");
//            } else {
//                System.out.println("Error Occured While Saving The Uploaded File In The Database... Please Check...!" + "\n");
//            }

        } else {
            System.out.print("Application Is Not Able To Bind With The Database! Please Check!");
        }

    }

这是Dao文件中的类映射器:

class PatientMapper implements RowMapper<Patient> {

    public Patient mapRow(ResultSet rs, int arg1) throws SQLException {
        Patient patient = new Patient();
        patient.setId_patient(rs.getInt("id_patient"));
        patient.setDescription(rs.getString("description"));

        Attachment attachment = new Attachment();
        attachment.setId_data(rs.getInt("id_data"));
        attachment.setData(rs.getBytes("file_data"));
        attachment.setPatientID(rs.getInt("patientID"));

        return patient;
    }
}

这是我处理保存文件的控制器:

@RequestMapping(value = "/AddPatient/{reqUserName}/add", method = RequestMethod.POST)
    public ModelAndView saveAddPatient(@ModelAttribute("patient") Patient patient,
                                       Attachment attachment,
                                       @PathVariable String reqUserName,
                                       SessionStatus status,
                                       HttpServletRequest request,
                                       final @RequestParam CommonsMultipartFile[] attachFileObj)
            throws IllegalStateException, IOException {

        // Determine If There Is An File Upload. If Yes, Attach It To The Client Email
        if ((attachFileObj != null) && (attachFileObj.length > 0) && (!attachFileObj.equals("")) &&
                (patient != null)) {
            for (CommonsMultipartFile aFile : attachFileObj) {
                if(aFile.isEmpty()) {
                    continue;
                } else {
                    System.out.println("Attachment Name?= " + aFile.getOriginalFilename() + "\n");
                    if (!aFile.getOriginalFilename().equals("")) {
                        patient = new Patient();
                        patient.setDescription(patient.getDescription());

                        attachment = new Attachment();
                        attachment.setData(aFile.getBytes());
//                        patient.setFileName(aFile.getOriginalFilename());

                        // Calling The Db Method To Save The Uploaded File In The Db
                        patientService.saveAttachment(patient, attachment);
                    }
                }
                System.out.println("File Is Successfully Uploaded & Saved In The Database.... Hurrey!\n");
            }
        } else {
            // Do Nothing
        }
        modelViewObj = new ModelAndView("success_Add_Patient","messageObj","Thank You! The File(s) Is Successfully Uploaded!");
        return  modelViewObj;


    }

当我运行代码并想通过上传文件夹来添加文件时,我得到了这个错误:

2018-07-18 15:43:47,390 [org.springframework.jdbc.support.SQLErrorCodesFactory]-[INFO] SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
2018-07-18 15:43:47,390 [org.springframework.jdbc.support.SQLErrorCodesFactory]-[DEBUG] Looking up default SQLErrorCodes for DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@3948e9ec]
2018-07-18 15:43:47,391 [org.springframework.jdbc.datasource.DataSourceUtils]-[DEBUG] Fetching JDBC Connection from DataSource
2018-07-18 15:43:47,391 [org.springframework.jdbc.datasource.DriverManagerDataSource]-[DEBUG] Creating new JDBC DriverManager Connection to [jdbc:mysql://143.167.11.2:3306/db_visualisation]
2018-07-18 15:43:47,636 [org.springframework.jdbc.datasource.DataSourceUtils]-[DEBUG] Returning JDBC Connection to DataSource
2018-07-18 15:43:47,637 [org.springframework.jdbc.support.SQLErrorCodesFactory]-[DEBUG] SQL error codes for 'MySQL' found
2018-07-18 15:43:47,638 [org.springframework.jdbc.support.SQLErrorCodesFactory]-[DEBUG] Caching SQL error codes for DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@3948e9ec]: database product name is 'MySQL'
2018-07-18 15:43:47,638 [org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator]-[DEBUG] Translating SQLException with SQL state '42000', error code '1064', message [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 'insert into attachment(id_data, file_data, patientID) values (_binary'Transition' at line 1]; SQL was [insert into patient(id_patient, description) values(?,?);insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));] for task [PreparedStatementCallback]
2018-07-18 15:43:47,639 [org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver]-[DEBUG] Resolving exception from handler [public org.springframework.web.servlet.ModelAndView com.Patient.controller.PatientController.saveAddPatient(com.Patient.pojo.Patient,com.Patient.pojo.Attachment,java.lang.String,org.springframework.web.bind.support.SessionStatus,javax.servlet.http.HttpServletRequest,org.springframework.web.multipart.commons.CommonsMultipartFile[]) throws java.lang.IllegalStateException,java.io.IOException]: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [insert into patient(id_patient, description) values(?,?);insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));]; nested exception is 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 'insert into attachment(id_data, file_data, patientID) values (_binary'Transition' at line 1
2018-07-18 15:43:47,641 [org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver]-[DEBUG] Resolving exception from handler [public org.springframework.web.servlet.ModelAndView com.Patient.controller.PatientController.saveAddPatient(com.Patient.pojo.Patient,com.Patient.pojo.Attachment,java.lang.String,org.springframework.web.bind.support.SessionStatus,javax.servlet.http.HttpServletRequest,org.springframework.web.multipart.commons.CommonsMultipartFile[]) throws java.lang.IllegalStateException,java.io.IOException]: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [insert into patient(id_patient, description) values(?,?);insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));]; nested exception is 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 'insert into attachment(id_data, file_data, patientID) values (_binary'Transition' at line 1
2018-07-18 15:43:47,641 [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver]-[DEBUG] Resolving exception from handler [public org.springframework.web.servlet.ModelAndView com.Patient.controller.PatientController.saveAddPatient(com.Patient.pojo.Patient,com.Patient.pojo.Attachment,java.lang.String,org.springframework.web.bind.support.SessionStatus,javax.servlet.http.HttpServletRequest,org.springframework.web.multipart.commons.CommonsMultipartFile[]) throws java.lang.IllegalStateException,java.io.IOException]: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [insert into patient(id_patient, description) values(?,?);insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));]; nested exception is 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 'insert into attachment(id_data, file_data, patientID) values (_binary'Transition' at line 1
2018-07-18 15:43:47,641 [org.springframework.web.servlet.handler.SimpleMappingExceptionResolver]-[DEBUG] Resolving exception from handler [public org.springframework.web.servlet.ModelAndView com.Patient.controller.PatientController.saveAddPatient(com.Patient.pojo.Patient,com.Patient.pojo.Attachment,java.lang.String,org.springframework.web.bind.support.SessionStatus,javax.servlet.http.HttpServletRequest,org.springframework.web.multipart.commons.CommonsMultipartFile[]) throws java.lang.IllegalStateException,java.io.IOException]: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [insert into patient(id_patient, description) values(?,?);insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));]; nested exception is 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 'insert into attachment(id_data, file_data, patientID) values (_binary'Transition' at line 1
2018-07-18 15:43:47,642 [org.springframework.web.servlet.handler.SimpleMappingExceptionResolver]-[DEBUG] Resolving to view 'error' for exception of type [org.springframework.jdbc.BadSqlGrammarException], based on exception mapping [java.lang.Exception]
2018-07-18 15:43:47,642 [org.springframework.web.servlet.handler.SimpleMappingExceptionResolver]-[DEBUG] Exposing Exception as model attribute 'exception'
2018-07-18 15:43:47,642 [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'error'; model is {exception=org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [insert into patient(id_patient, description) values(?,?);insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));]; nested exception is 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 'insert into attachment(id_data, file_data, patientID) values (_binary'Transition' at line 1}
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [insert into patient(id_patient, description) values(?,?);insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));]; nested exception is 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 'insert into attachment(id_data, file_data, patientID) values (_binary'Transition' at line 1
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1402)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:620)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:850)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:905)
    at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:915)
    at com.Patient.dao.PatientDaoImpl.saveAttachment(PatientDaoImpl.java:142)
    at com.Patient.service.PatientServiceImpl.saveAttachment(PatientServiceImpl.java:68)
    at com.Patient.controller.PatientController.saveAddPatient(PatientController.java:103)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: 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 'insert into attachment(id_data, file_data, patientID) values (_binary'Transition' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
    at com.mysql.jdbc.Util.getInstance(Util.java:372)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3835)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3771)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2535)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1911)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2145)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2081)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2066)
    at org.springframework.jdbc.core.JdbcTemplate.lambda$update$0(JdbcTemplate.java:855)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)
    ... 43 more
2018-07-18 15:43:47,646 [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[DEBUG] Invoking afterPropertiesSet() on bean with name 'error'
2018-07-18 15:43:47,646 [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Rendering view [org.springframework.web.servlet.view.JstlView: name 'error'; URL [/WEB-INF/views/error.jsp]] in DispatcherServlet with name 'spring-mvc'
2018-07-18 15:43:47,646 [org.springframework.web.servlet.view.JstlView]-[DEBUG] Added model object 'reqUserName' of type [java.lang.String] to request in view with name 'error'
2018-07-18 15:43:47,646 [org.springframework.web.servlet.view.JstlView]-[DEBUG] Added model object 'exception' of type [org.springframework.jdbc.BadSqlGrammarException] to request in view with name 'error'
2018-07-18 15:43:47,646 [org.springframework.web.servlet.view.JstlView]-[DEBUG] Forwarding to resource [/WEB-INF/views/error.jsp] in InternalResourceView 'error'
2018-07-18 15:43:47,650 [org.springframework.web.multipart.commons.CommonsMultipartResolver]-[DEBUG] Cleaning up multipart file [attachFileObj] with original filename [PA_Not_worn.csv], stored in memory
2018-07-18 15:43:47,650 [org.springframework.web.multipart.commons.CommonsMultipartResolver]-[DEBUG] Cleaning up multipart file [attachFileObj] with original filename [flipDetection.csv], stored in memory
2018-07-18 15:43:47,650 [org.springframework.web.multipart.commons.CommonsMultipartResolver]-[DEBUG] Cleaning up multipart file [attachFileObj] with original filename [EE_NotWorn.csv], stored in memory
2018-07-18 15:43:47,650 [org.springframework.web.multipart.commons.CommonsMultipartResolver]-[DEBUG] Cleaning up multipart file [attachFileObj] with original filename [PA_Shuffling.csv], stored in memory
2018-07-18 15:43:47,650 [org.springframework.web.multipart.commons.CommonsMultipartResolver]-[DEBUG] Cleaning up multipart file [attachFileObj] with original filename [EE_Moderate.csv], stored in memory
2018-07-18 15:43:47,650 [org.springframework.web.multipart.commons.CommonsMultipartResolver]-[DEBUG] Cleaning up multipart file [attachFileObj] with original filename [EE_Recommendations.csv], stored in memory
2018-07-18 15:43:47,650 [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Successfully completed request

这是数据库中的表:

任何人都可以帮助我,如何解决这个问题?以便我可以将csv文件组成的文件夹上传到数据库mysql?

共有2个答案

唐修能
2023-03-14

插入sql有很多地方需要更改:

a.当使用< code>INSERT INTO时,只能使用< code>SELECT,在这种情况下,还需要删除关键字< code >值

b.需要删除<代码>;在sql的结尾

c.不能在一个sql中执行两个< code>INSERT INTO

所以改变

  String sql = "insert into patient(id_patient, description) values(?,?);" 
           + "insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));";

到两个单独的sql

  String sqlA = "insert into patient(id_patient, description) values(?,?)";
  String sqlB = "insert into attachment(id_data, file_data, patientID) 
      values(?,?,?);

在这种情况下,您需要为每个 sql 调用 jdbcTemplate.update() 两次

司马高昂
2023-03-14

我不认为您可以同时运行这两个:

if(null != jdbcTemplate) {
            // Performing The Sql 'Insert' Operation
            String sql = "insert into patient(id_patient, description) values(?,?);" +
                    "insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));";


            jdbcTemplate.update(sql, patient.getDescription(), attachment.getId_data(), attachment.getData(), attachment.getPatientID());

也许可以尝试:

    if(null != jdbcTemplate) {
                // Performing The Sql 'Insert' Operation
                String sql = "insert into patient(id_patient, description) values(?,?);"; 

                String sqlTwo = "insert into attachment(id_data, file_data, patientID) values (?, ?, (select patientID from patient where patientID = id_patient));";


jdbcTemplate.update(sql, patient.getDescription(), attachment.getId_data(), attachment.getData(), attachment.getPatientID());

jdbcTemplate.update(sqlTwo, patient.getDescription(), attachment.getId_data(), attachment.getData(), attachment.getPatientID());

不能用嵌套子查询绑定参数:

values (?, ?, (select patientID from patient where patientID = id_patient))
 类似资料:
  • 我正试图上传一个文件到我的谷歌硬盘,下面的代码工作。如何指定要上载到哪个文件夹,即驱动器--shared with me--csvFolder

  • 我试图寻找'jpg,jpeg,png'文件在我的USB驱动器,并试图将它们一个接一个地移动到一个新的文件夹。请让我知道这里有什么问题。 错误:- 目标目录E\Mac\MovedPics不存在语音指令2。zip:E:\Mac目的地目录E\Mac\MovedPics不存在usbpicsdata。txt:E:\Mac REGEXP匹配:-E:\Mac\4。jpg回溯(最近一次调用last):文件“C:\

  • 我正在使用node的开发者工具包将图像上传到AWS S3: 这是可行的,但我如何才能使图像上传到一个特定的文件夹中的桶?

  • 根据SkyDrive api(http://msdn.microsoft.com/en-us/library/live/hh826531.aspx#uploading_files),我在帖子请求的正文中以字节[]传递图像的内容。文件创建发生在skyDrive服务器上,但当我在skyDrive中打开它时,它说“文件应用程序被损坏或损坏”。 请求的正文 --A300x内容处理:表单数据;name=“f

  • 我尝试使用C#将文件上传到FTP服务器。文件已上传,但字节为零。

  • 我想添加时间字符串的文件名,我上传到谷歌驱动器使用pydrive的结束。基本上,我尝试编写以下代码,但我不知道如何适应新的文件变量: 获取类型错误:应为str、字节或os。类路径对象,而不是GoogleDriveFile

  • 我是一个相当新的java程序员。我只有大约五周的经验,从零开始,如果在Scene Builder中创建的javafx fxml文件与controller类不在同一个文件夹中,我就会遇到问题,无法正确加载这些文件。 我正在使用 我试着自己研究这个问题,但我没有得到太多,这里的几个答案似乎相似,似乎没有帮助,或者我太密集和/或没有经验,弄不明白它们的意义。它们是JavaFX2.0加载带有事件处理程序的

  • 方法:获取 现状:404 注意:URL应该是http://localhost:8080/dragonline/resources/img/icon.png()