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:
urlthe jdbc url connect to.
dbtablejdbc table should read. note valid infromclause of sql query can used. example, instead of full table use subquery in parentheses.driverclass name of jdbc driver needed connect url. class loaded on master , workers before running jdbc commands allow driver register jdbc subsystem.partitioncolumn,lowerbound,upperbound,numpartitionsthese 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
Post a Comment