Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ final class DataFrameWriter private[sql](df: DataFrame) {
if (!tableExists) {
val schema = JdbcUtils.schemaString(df, url)
val sql = s"CREATE TABLE $table ($schema)"
conn.prepareStatement(sql).executeUpdate()
conn.createStatement.executeUpdate(sql)
}
} finally {
conn.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private[sql] object JDBCRDD extends Logging {
val dialect = JdbcDialects.get(url)
val conn: Connection = getConnector(properties.getProperty("driver"), url, properties)()
try {
val rs = conn.prepareStatement(s"SELECT * FROM $table WHERE 1=0").executeQuery()
val rs = conn.createStatement.executeQuery(s"SELECT * FROM $table WHERE 1=0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah hang on a sec, I see you've changed some non-DDL statements in this version of the PR. The change is just about avoiding PreparedStatement for DDL right? My earlier comments were about closing resources for a bunch of queries including non-DDL. But if you're only addressing DDL, then your last PR was fine (before it was corrupted).

try {
val rsmd = rs.getMetaData
val ncols = rsmd.getColumnCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ object JdbcUtils extends Logging {
// Somewhat hacky, but there isn't a good way to identify whether a table exists for all
// SQL database systems using JDBC meta data calls, considering "table" could also include
// the database name. Query used to find table exists can be overriden by the dialects.
Try(conn.prepareStatement(dialect.getTableExistsQuery(table)).executeQuery()).isSuccess
Try(conn.createStatement.executeQuery(dialect.getTableExistsQuery(table))).isSuccess
}

/**
* Drops a table from the JDBC database.
*/
def dropTable(conn: Connection, table: String): Unit = {
conn.prepareStatement(s"DROP TABLE $table").executeUpdate()
conn.createStatement.executeUpdate(s"DROP TABLE $table")
}

/**
Expand Down