title: How to read data from mariadb using Spark java
body: <p>I need to read a table from MariaDB by using Spark and Java.</p>
  
  <p>I wrote a Java code for read table data from database.The connection is established successfully but it produces an error while reading the data. I am trying to read the table data as a dataframe. But the column name is shown as column value in result. find the code given below:</p>
  
  <pre><code>import java.io.IOException;
  import java.io.InputStream;
  import java.util.Properties;
  import org.apache.spark.sql.Dataset;
  import org.apache.spark.sql.Row;
  import org.apache.spark.sql.SparkSession;
  import static org.apache.spark.sql.functions.col;
  
  public class mariadb_to_csv {    
  public static void main(String[] args) {
  
      Properties prop = new Properties();
      String resourceName = "config.properties";
          ClassLoader loader = Thread.currentThread().getContextClassLoader();
          try(InputStream resourceStream = loader.getResourceAsStream(resourceName)) {
              prop.load(resourceStream);
          } catch (IOException e) {
              e.printStackTrace();
          }
      SparkSession spark = SparkSession.builder()
              .appName("Java Spark SQL basic example")
              .config("spark.some.config.option", "some-value").getOrCreate();
  
      Dataset&lt;Row&gt; jdbcDF = spark.read().format("jdbc")
              .option("url","url_address")
              .option("driver", "org.mariadb.jdbc.Driver")
              .option("dbtable", "source_table")
              .option("user", "username")
              .option("password", "password")
              .load();
      jdbcDF.select(col("code"), col("name"), col("isActive"), col("createdByUser"), col("modifiedByUser")).show();       
  
  
       }
       }  
  </code></pre>
  
  <p>In result, the column value is duplicated in column name.</p>
  
  <p><a href="https://i.stack.imgur.com/Zaqtm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zaqtm.jpg" alt="error image"></a></p>
  
  <p>Whats wrong with this?</p>