Hi All,
We are exploring insertion into RDBMS(SQL Server) through Spark by JDBC
Driver. The excerpt from the code is as follows :
We are doing insertion inside an action :
Integer res = flatMappedRDD.reduce(new Function2<Integer,Integer,Integer>(){
//@Override
public Integer call(Integer arg0, Integer arg1) throws Exception {
url =
"jdbc:jtds:sqlserver://10.189.220.12:1433/exampleDB";
jdbcdriver = "com.mysql.jdbc.Driver";
USER = "clienta";
PASS = "clienta";
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
con = DriverManager.getConnection(url, USER, PASS);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Statement s = con.createStatement();
System.out.println("Inserting into DB : - " + (arg0 + arg1));
String sql = "INSERT INTO Table_1 VALUES("+(arg0 + arg1)+")";
s.executeUpdate(sql);
}
1) Is this the right way to this ?
2) Does every node creates a new connection object ? If Yes, is there a
overhead of multiple connection
object creations ? How to resolve this ?
3) What is the best practice to create a connection object for insertion or
general update into Database using spark ?
Thanks
Nitin
--
View this message in context:
http://apache-spark-user-list.1001560.n3.nabble.com/Spark-and-insertion-into-RDBMS-NoSQL-tp18717.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]