Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of connecting mysql with SparkSQL JDBC

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "SparkSQL JDBC connection mysql method", in the daily operation, I believe many people in SparkSQL JDBC connection mysql method problems exist doubts, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "SparkSQL JDBC connection mysql method" doubts helpful! Next, please follow the small series to learn together!

SparkSQL JDBC connection mysql1. import/home/eric/bigdata/spark-log-analysis/mysql-connector-java-5.1.38.jar2. code as follows package logimport java.sql.DriverManagerimport java.sql.Connection/** * SparkSQL JDBC Connection mysql * Created by eric on 16/6/30. */object ScalaJdbcConnectSelect { def main(args: Array[String]) { val driver = "com.mysql.jdbc.Driver" val url = "jdbc:mysql://127.0.0.1/myapp" val username = "root" val password = "" var connection:Connection = null try { Class.forName(driver) connection = DriverManager.getConnection(url, username, password) val statement = connection.createStatement() val resultSet = statement.executeQuery("SELECT * FROM sys_user_base limit 5") while ( resultSet.next() ) { val id = resultSet.getInt("id") val user_id = resultSet.getString("user_id") println("id = " + id + ", user_id = " + user_id) } } catch { case e => e.printStackTrace } connection.close() }}3. The results are as follows

At this point, the study of "SparkSQL JDBC connection mysql method" is over, I hope to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report