Kotlin-Exposed在他们的wiki上的例子是行不通的

这段代码被直接从Kotlin-Exposed Wiki中删除,但不起作用。 奇怪和沮丧,我不能得到它的工作,因为我有一个很酷的项目,需要使用RDBMS的想法。 我错过了什么? 它坏了吗?

import org.jetbrains.exposed.sql.StdOutSqlLogger import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.Table import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.selectAll fun main(args: Array) { Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") transaction { logger.addLogger(StdOutSqlLogger) val stPeteId = Cities.insert { it[name] = "St. Petersburg" } get Cities.id println("Cities: ${Cities.selectAll()}") } } // Table definition object Cities : Table() { val id = integer("id").autoIncrement().primaryKey() val name = varchar("name", 50) } // Entity definition data class City( val id: Int, val name: String ) 

在Intellij中运行时,我收到以下错误消息:

 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Exception in thread "main" org.h2.jdbc.JdbcSQLException: Table "CITIES" not found; SQL statement: INSERT INTO CITIES (NAME) VALUES (?) [42102-196] at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) at org.h2.message.DbException.get(DbException.java:179) at org.h2.message.DbException.get(DbException.java:155) at org.h2.command.Parser.readTableOrView(Parser.java:5552) at org.h2.command.Parser.readTableOrView(Parser.java:5529) at org.h2.command.Parser.parseInsert(Parser.java:1062) at org.h2.command.Parser.parsePrepared(Parser.java:417) at org.h2.command.Parser.parse(Parser.java:321) at org.h2.command.Parser.parse(Parser.java:293) at org.h2.command.Parser.prepareCommand(Parser.java:258) at org.h2.engine.Session.prepareLocal(Session.java:578) at org.h2.engine.Session.prepareCommand(Session.java:519) at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1204) at org.h2.jdbc.JdbcPreparedStatement.(JdbcPreparedStatement.java:73) at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:288) at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:1188) at org.jetbrains.exposed.sql.statements.InsertStatement.prepared(InsertStatement.kt:58) at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed(Statement.kt:46) at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:103) at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:97) at org.jetbrains.exposed.sql.statements.Statement.execute(Statement.kt:27) at org.jetbrains.exposed.sql.QueriesKt.insert(Queries.kt:43) at MainKt$main$1.invoke(Main.kt:14) at MainKt$main$1.invoke(Main.kt) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:92) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:64) at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:55) at MainKt.main(Main.kt:11) Process finished with exit code 1 

    One Solution collect form web for “Kotlin-Exposed在他们的wiki上的例子是行不通的”

    我认为他们的例子中缺少创造性声明。 项目的GitHub页面上的 DAO例子似乎有几个陈述,你指的例子没有。

    尝试添加一个创建语句:

     fun main(args: Array) { Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver") transaction { logger.addLogger(StdOutSqlLogger) // ADD THIS - Create tables create (Cities) val stPeteId = Cities.insert { it[name] = "St. Petersburg" } get Cities.id println("Cities: ${Cities.selectAll()}") } } 

    如果这样做,我敢打赌,他们会接受公关文件。

    Kotlin language will be the best programming language for Android.