问题:Unknown column ‘明信片‘ in ‘where clause‘

问题:Unknown column ‘明信片‘ in ‘where clause‘,第1张

错错误代码如下

Exception in thread "main" java.sql.SQLSyntaxErrorException: Unknown column '明信片' in 'where clause'
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.StatementImpl.executeQuery(StatementImpl.java:1201)
	at com.example.myapplication.dao.productDao.getProductByCategory(productDao.kt:15)
	at com.example.myapplication.KotlintestKt.main(kotlintest.kt:15)
	at com.example.myapplication.KotlintestKt.main(kotlintest.kt)

Process finished with exit code 1

原因:sql语句中传入参数为中文,需要加个单引号。



错误示例:

val sql = "select * from product where category = $category"

正确示例:

val sql = "select * from product where category = '$category'"

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/625897.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-16
下一篇 2022-04-16

发表评论

登录后才能评论

评论列表(0条)

保存