简体   繁体   English

有关Spring应用程序中JDBC中的SQL指令的一些信息

[英]Some information about SQL instruction in JDBC in a Spring application

I am studying how to implement CRUD operation on a database in Spring using JDBC following this tutorial: http://www.tutorialspoint.com/spring/spring_jdbc_example.htm 我正在研究如何使用JDBC在本教程中使用JDBC在数据库上实现CRUD操作: http//www.tutorialspoint.com/spring/spring_jdbc_example.htm

It is quite clear but I have only a doubt about how the SQL query are specified: 很明显但我对如何指定SQL查询只有疑问:

For example, in the create() method of my StudentJDBCTemplate clase the query is declared in the following way: 例如,在StudentJDBCTemplate clase的create()方法中,查询以下列方式声明:

String SQL = "insert into Student (name, age) values (?, ?)"; 

this is quite different from the classi SQL statment that is: 这与classi SQL语句完全不同,它是:

insert into Student("Andrea", 25);

I have read about the use of the "?" 我读过有关“?”的用法 placeholder that is used to prevent SQL injection and I have understand how this insert instruction work (it is very intuitive...) 用于防止SQL注入的占位符,我已经理解了这个插入指令是如何工作的(它非常直观......)

I would only know if the instruction used in this tutorial is JDBC or Spring specific form or what about it? 我只知道本教程中使用的指令是JDBC还是Spring特定的形式或者它是什么?

Thank you 谢谢

Andrea 安德里亚

Prepared statements using ? 准备好的陈述使用? as a placeholder for parameters are a standard JDBC feature. 作为参数的占位符是标准JDBC功能。 Read the JDBC tutorial (and the JDBC javadoc) to understand what JDBC offers. 阅读JDBC教程 (和JDBC javadoc)以了解JDBC提供的内容。

Spring-JDBC adds JdbcTemplate over plain JDBC, which helps in handling exceptions, closing resources, generate objects from rows, etc. It also adds support for named parameters, which are not supported by plain JDBC. Spring-JDBC在纯JDBC上添加JdbcTemplate,这有助于处理异常,关闭资源,从行生成对象等。它还增加了对命名参数的支持,普通JDBC不支持这些参数。

Classes in the packages java.sql and javax.sql are standard Java classes. java.sqljavax.sql中的类是标准Java类。 Classes in the package org.springframework are Spring-specific classes. org.springframework包中的类是特定于Spring的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM