在使用 PostgreSQL 在 MyBatis 中运行 select 时出现此错误:
\n\n### The error may exist in data/mapper.xml\n### The error may involve Transaccion.selectDeFraude-Inline\n### The error occurred while setting parameters\n### SQL: SELECT transaction_id, card_number, transaction_date, fraud FROM transactions.? ORDER BY card_number, transaction_date ASC;\n### Cause: org.postgresql.util.PSQLException: ERROR: error de sintaxis en o cerca de \xc2\xab$1\xc2\xbb\nRun Code Online (Sandbox Code Playgroud)\n\n我在 mapper.xml 中收到错误:
\n\n<select id="selectDeFraude" parameterType="String" resultMap="result">\n SELECT transaction_id, card_number, transaction_date, fraud FROM transactions.#{tabla} ORDER BY card_number, transaction_date ASC;\n</select>\nRun Code Online (Sandbox Code Playgroud)\n\n这是调用 select 的方法:
\n\npublic List<Transaccion> selectDeFraude(String tabla){\n\n …Run Code Online (Sandbox Code Playgroud) 我在 Springboot 2.0 中的 ibatis 中遇到日期比较错误,我没有主意了。
我的映射器看起来像这样(使用 MySql):
@Select("select count(s.id,r.date) from eshrsys.score s join eshrsys.round on (s.round_id = r.id) where r.date > '#{date,jdbcType=DATE}'")
Integer getScoreCountFromDate(Date date);
Run Code Online (Sandbox Code Playgroud)
我正在传递一个不为空的有效 java.sql.date 对象。但我在引用日期比较时遇到此错误:
2018-09-02 21:14:23.999 ERROR 5644 --- [nio-8088-exec-2] oaccC[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] 在上下文中path[]抛出异常[请求处理失败;嵌套异常是 org.mybatis.spring.MyBatisSystemException:嵌套异常是 org.apache.ibatis.type.TypeException:无法设置映射参数:ParameterMapping{property='date',mode=IN,javaType=class java.sql。日期,jdbcType=DATE,numericScale=null,resultMapId='null',jdbcTypeName='null',表达式='null'}。原因:org.apache.ibatis.type.TypeException:使用 JdbcType DATE 为参数 #1 设置非 null 时出错。尝试为此参数设置不同的 JdbcType 或不同的配置属性。原因:java.sql.SQLException:参数索引超出范围(1 > 参数数量,即 0)。]
我尝试了许多不同的解决方法,从在发送输入之前将输入转换为字符串,到删除单引号,再到使用 jdbcType。没有任何效果。
我目前构建一个应用程序使用spring作为框架.我想用spring测试批处理事务.这是我的代码:
public class SqlMapTestDao extends SqlMapClientDaoSupport implements TestDao {
public List<Test> getAllTest() {
return getSqlMapClientTemplate().queryForList("getAllTest");
}
public Test getTest(int param) {
return (Test)getSqlMapClientTemplate().queryForObject("getTest" , param);
}
public void insertTest(Test test) {
getSqlMapClientTemplate().insert("insertTest", test);
}
@Transactional(readOnly = false)
public void insertBatch(List<Test> batch) throws SQLException{
for(Test test : batch) {
getSqlMapClientTemplate().insert("insertTest", test);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试插入与下面相同的主键.
@Autowired
private TestDao testDao;
@RequestMapping(value="/", method=RequestMethod.GET)
public String home(@ModelAttribute Account acc) {
List<Test> test = new ArrayList<Test>();
test.add(new Test(7, "ini empat"));
test.add(new Test(1, "ini satu"));
test.add(new …Run Code Online (Sandbox Code Playgroud) 目前我遇到了一个问题,我一直在进行大量搜索,但仍未找到答案。
问题的背景:我们在一个 URL 上有多个 DB 模式,包括模式的测试副本(例如,schema1、schema2、schema1_test、schema2_test 都在同一个 URL)。我正在尝试通过属性文件使每个架构的哪个版本使用可配置。
我们正在使用 Spring 和 mybatis,不幸的是我对这两个都是新手(所以请原谅我的无知或我在描述问题时犯的任何错误!)
所以在我的 spring 配置文件中,它存储在 /src/main/resources 下,我有以下片段:(我只添加了“configLocation”属性,后来添加了“sqlSessionFactoryBeanName”属性)
<!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.example.domain" />
<property name="configLocation" value="classpath:mybatisConfig.xml" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.example.something.persistence" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
Run Code Online (Sandbox Code Playgroud)
我的mybatisConfig.xml(存放在/src/main/resources下,应该在类路径下)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="sqlmapconfig.properties" />
</configuration>
Run Code Online (Sandbox Code Playgroud)
sqlmapconfig.properties(在同一文件夹中)
schema1=schema1_test
Run Code Online (Sandbox Code Playgroud)
我尝试在 …
我想使用动态sql语句,仅当变量不为null且大于零时才执行.像这样:
<isNotNull prepend="AND" property="ProprietaryId">
<isGreaterThan prepend="AND" property="ProprietaryId" compareValue="0">
G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>
Run Code Online (Sandbox Code Playgroud)
但没有预先加两个'AND'.
我已经阅读了文档,但没有找到好的例子.
我使用 SqlServer 和 MyBatis。
一直在网上寻找几个例子,但似乎没有什么适合我的需要。storage_procedure Im 调用接受 5 个参数并返回 1 个值 - 例如
give_discount(名字、姓氏、性别、出生日期、年龄)
所有这些都是字符串。storage_procedure 然后返回一个 STRING,它应该告诉你你有权享受多少折扣。
这五个属性(FirstName、LastName、DateOfBirth、Age、Gender)存储在名为 Person.java 的 POJO 中
所以假设我创建了一个 Person.java 的实例
Person person1 = new Person();
person1.setFirstName("Joe");
person1.setLastName("Higashi");
person1.setGender("M");
person1.setDateOfBirth("1990-01-01");
person1.setAge("29");
Run Code Online (Sandbox Code Playgroud)
这是我的 mapperXML
<resultMap id = "discountValueParams" type="com.test.Person">
<result property = "FirstName" column = "FirstName"/>
<result property = "LastName" column = "LastName"/>
<result property = "Gender" column = "Gender"/>
<result property = "DateOfBirth" column = "DateOfBirth"/>
<result property = "Age" column = "Age"/>
</resultMap>
Run Code Online (Sandbox Code Playgroud)
所以问题是:
如何将 …
ibatis ×6
mybatis ×4
java ×3
spring ×2
mysql ×1
postgresql ×1
rollback ×1
spring-boot ×1
sql ×1
xml ×1