How to pass username and password to Spark-SQL when using JDBC data source? -


i started use spark-sql load data h2 database, here did following spark-sql document:

>>> sqlcontext = sqlcontext(sc) >>> df = sqlcontext.load(source="jdbc",driver="org.h2.driver", url="jdbc:h2:~/test", dbtable="rawvector") 

but didn't work , gave errors, think problem username , password not specified in function.

this parameters document spark-sql 1.3.1:

  1. url

    the jdbc url connect to.

  2. dbtable jdbc table should read. note valid in from clause of sql query can used. example, instead of full table use subquery in parentheses.

  3. driver class name of jdbc driver needed connect url. class loaded on master , workers before running jdbc commands allow driver register jdbc subsystem.

  4. partitioncolumn, lowerbound, upperbound, numpartitions

    these options must specified if of them specified. describe how partition table when reading in parallel multiple workers. partitioncolumn must numeric column table in question.

but didn't find clue how pass database user name , password sqlcontext.load function. 1 has similar case or clues?

thanks.

i figured out. do

df = sqlcontext.load(   source="jdbc",driver="org.h2.driver",   url="jdbc:h2:tcp://localhost/~/test?user=sa&password=1234",   dbtable="rawvector" ) 

and when create database, use same pattern:

conn = drivermanager.getconnection(   "jdbc:h2:tcp://localhost/~/"+dbname+"?user=sa&password=1234", null, null ); 

and, here blog how use api.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -