错错误代码如下
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'"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)