• <bdo id='8yzBA'></bdo><ul id='8yzBA'></ul>
    <legend id='8yzBA'><style id='8yzBA'><dir id='8yzBA'><q id='8yzBA'></q></dir></style></legend>

    <tfoot id='8yzBA'></tfoot>

      <small id='8yzBA'></small><noframes id='8yzBA'>

    1. <i id='8yzBA'><tr id='8yzBA'><dt id='8yzBA'><q id='8yzBA'><span id='8yzBA'><b id='8yzBA'><form id='8yzBA'><ins id='8yzBA'></ins><ul id='8yzBA'></ul><sub id='8yzBA'></sub></form><legend id='8yzBA'></legend><bdo id='8yzBA'><pre id='8yzBA'><center id='8yzBA'></center></pre></bdo></b><th id='8yzBA'></th></span></q></dt></tr></i><div id='8yzBA'><tfoot id='8yzBA'></tfoot><dl id='8yzBA'><fieldset id='8yzBA'></fieldset></dl></div>
    2. 使用 SparkSQL 删除 MySQL 表

      时间:2023-08-22

        <small id='RWDOi'></small><noframes id='RWDOi'>

          1. <tfoot id='RWDOi'></tfoot>

            <i id='RWDOi'><tr id='RWDOi'><dt id='RWDOi'><q id='RWDOi'><span id='RWDOi'><b id='RWDOi'><form id='RWDOi'><ins id='RWDOi'></ins><ul id='RWDOi'></ul><sub id='RWDOi'></sub></form><legend id='RWDOi'></legend><bdo id='RWDOi'><pre id='RWDOi'><center id='RWDOi'></center></pre></bdo></b><th id='RWDOi'></th></span></q></dt></tr></i><div id='RWDOi'><tfoot id='RWDOi'></tfoot><dl id='RWDOi'><fieldset id='RWDOi'></fieldset></dl></div>

              <tbody id='RWDOi'></tbody>
              <bdo id='RWDOi'></bdo><ul id='RWDOi'></ul>
              <legend id='RWDOi'><style id='RWDOi'><dir id='RWDOi'><q id='RWDOi'></q></dir></style></legend>

                本文介绍了使用 SparkSQL 删除 MySQL 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我知道我们可以通过以下命令从 SparkSQL 查询或创建一个 Mysql 表.

                I know that we can query or create a Mysql table from SparkSQL through the below commands.

                val data = sqlContext.read.jdbc(urlstring, tablename, properties)
                data.write.format("com.databricks.spark.csv").save(result_location)
                
                val dataframe = sqlContext.read.json("users.json")
                dataframe.write.jdbc(urlstring, table, properties)
                

                这样有没有办法删除一个表?

                Like that is there any way to drop a table ?

                推荐答案

                您可以尝试使用 JDBC 驱动程序进行基本的 DROP 操作:

                You can try a basic DROP operation with the JDBC driver :

                val DB_URL: String = ???
                val USER: String = ???
                val PASS: String = ???
                
                def dropTable(tableName: String) = {
                
                    import java.sql._;
                
                    var conn: Connection = null;
                    var stmt: Statement = null;
                
                    try {
                      Class.forName("com.mysql.jdbc.Driver");
                      println("Connecting to a selected database...");
                      conn = DriverManager.getConnection(DB_URL, USER, PASS);
                      println("Connected database successfully...");
                      println("Deleting table in given database...");
                      stmt = conn.createStatement();
                      val sql: String = s"DROP TABLE ${tableName} ";
                      stmt.executeUpdate(sql);
                      println(s"Table ${tableName} deleted in given database...");
                    } catch {
                      case e: Exception => println("exception caught: " + e);
                    } finally {
                      ???
                    }
                }
                
                dropTable("test")
                

                您可以使用 JDBCUtils 在 Spark 中做到这一点,但这非常简单.

                You can do that with Spark using JDBCUtils but this is quite straightforward.

                这篇关于使用 SparkSQL 删除 MySQL 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Spark在执行jdbc保存时给出空指针异常 下一篇:分解表以按列进行透视(SQL、PYSPARK)

                相关文章

                最新文章

                1. <small id='miK3h'></small><noframes id='miK3h'>

                    <bdo id='miK3h'></bdo><ul id='miK3h'></ul>
                2. <tfoot id='miK3h'></tfoot>
                    <legend id='miK3h'><style id='miK3h'><dir id='miK3h'><q id='miK3h'></q></dir></style></legend>
                    <i id='miK3h'><tr id='miK3h'><dt id='miK3h'><q id='miK3h'><span id='miK3h'><b id='miK3h'><form id='miK3h'><ins id='miK3h'></ins><ul id='miK3h'></ul><sub id='miK3h'></sub></form><legend id='miK3h'></legend><bdo id='miK3h'><pre id='miK3h'><center id='miK3h'></center></pre></bdo></b><th id='miK3h'></th></span></q></dt></tr></i><div id='miK3h'><tfoot id='miK3h'></tfoot><dl id='miK3h'><fieldset id='miK3h'></fieldset></dl></div>