I am trying to load data in hive through a java program. I am loading the file from my machine.
stmt.executeQuery("load data local inpath 'file:///C:/sample/Documents/sample1.txt' into table " + tablename);
When I execute this program I am getting the following exception
Caused by: java.lang.RuntimeException: java.net.URISyntaxException:Expected scheme-specific part at index 2: C:
at java.net.URI$Parser.fail(URI.java:2829)
at java.net.URI$Parser.failExpecting(URI.java:2835)
at java.net.URI$Parser.parse(URI.java:3038)
at java.net.URI.<init>(URI.java:753)
However when I execute the program in a ubuntu machine
stmt.executeQuery("load data local inpath '/home/sample/sample1.txt' into table " + tablename);
The data is loaded correctly to the hive database.
When I execute the program in windows I am getting the exception. How can I solve this?
Path(Uri) syntax in windows is different from ubuntu. In ubuntu we use forward slash where as in windows we use backslash.
Windows: C:\Users\system\Desktop\db
Linux: /home/sample/sample1.txt'
So try changing the syntax of the uri.
Related
I am trying to migrate from MySQL to PostgreSQL and I have a Java-related problem that I am not able to fix. Full disclosure: I know little or nothing about Java, but the migration uses a Java-based script, so for me it becomes a configuration problem.
Short version of the problem:
The migration tool throws this exception:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
mysql-connector-java-5.0.8-bin.jar is already in the "JAVA_HOME\jre\lib\ext" directory, and I don't know how to solve this depencency problem.
Long version of the problem:
I was trying to migrate from MySQL to PostgreSQL. I checked the official postgresql documentation and I chose the free tool from entreprisedb (that can be downloaded here) to start the migration.
From the installation readme, they tell you that the mysql connector is not installed by default, but they also tell you the steps to solve this problem:
To enable MySQL connectivity, download MySQL's freely available JDBC driver from:
http://www.enterprisedb.com/downloads/third-party-jdbc-drivers
Place the mysql-connector-java-5.0.8-bin.jar file in the "JAVA_HOME\jre\lib\ext" directory (in my case: "C:\Program Files\Java\jre1.8.0_60\lib\ext\mysql-connector-java-5.0.8-bin.jar").
After configuring the tool properly and executing the .bat, this is the error I get:
Connecting with source MySQL database server...
MTK-11009: Error Connecting Database "MySQL Server"
DB-null: java.sql.SQLException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Stack Trace:
com.edb.MTKException: MTK-11009: Error Connecting Database "MySQL Server"
at com.edb.dbhandler.mysql.MySQLConnection.<init>(MySQLConnection.java:48)
at com.edb.common.MTKFactory.createMTKConnection(MTKFactory.java:250)
at com.edb.MigrationToolkit.createNewSourceConnection(MigrationToolkit.java:5982)
at com.edb.MigrationToolkit.initToolkit(MigrationToolkit.java:3346)
at com.edb.MigrationToolkit.main(MigrationToolkit.java:1700)
Caused by: java.sql.SQLException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at com.edb.Utility.processException(Utility.java:327)
at com.edb.dbhandler.mysql.MySQLConnection.<init>(MySQLConnection.java:47)
... 4 more
...which, to my understanding, probably means that mysql-connector-java-5.0.8-bin.jar is not found.
All the links I've found online regarding the error are specific for Eclipse or other IDEs, so I have not yet been able to solve this dependency problem.
SOLUTION
With the help of a friend that masters Java, this is the solution he achieved:
To start looking for the problem, we opened the runMTK.bat. The execution line reads:
cscript //nologo "..\etc\sysconfig\runJavaApplication.vbs" "..\etc\sysconfig\edbmtk-49.config" "-Dprop=..\etc\toolkit.properties -classpath -jar edb-migrationtoolkit.jar %*"
So then we opened this runJavaApplication.vbs, and in order to know the JAVA_EXECUTABLE_PATH that the program was using, we add this line to the script:
Wscript.Echo "JAVA_EXECUTABLE_PATH = " & JAVA_EXECUTABLE_PATH
With that info, we discover that the script is using the Java folder under C:\Program Files (x86), instead of the one under C:\Program Files (where I dropped the mysql jar). So we copy the mysql-connector-java-5.0.8-bin.jar in the \ext folder of the x86, and now the script works.
Word of advice: the script is throwing errors in half of the exported tables, so all the hassle may not be worth it. BUT if anyone is interested in making this migration script work from A to Z (which has been quite a challenge), here are the details:
HOW TO
Free tool (from entreprisedb):
http://www.enterprisedb.com/downloads/postgres-postgresql-downloads
Extract the files from the zip and fun the installer (ppasmeta-9.5.0.5-windows-x64.exe) as administrator.
To enable MySQL connectivity, download MySQL's freely available JDBC driver from:
http://www.enterprisedb.com/downloads/third-party-jdbc-drivers
Place the mysql-connector-java-5.0.8-bin.jar file in the "JAVA_HOME\jre\lib\ext" directory (in my case: "C:\Program Files\Java\jre1.8.0_60\lib\ext\mysql-connector-java-5.0.8-bin.jar").
The Migration Toolkit documentation can be found:
here (online doc): https://www.enterprisedb.com/docs/en/9.4/migrate/toc.html
or here (pdf doc): http://get.enterprisedb.com/docs/Postgres_Plus_Migration_Guide_v9.5.pdf
First: modify C:\Program Files\PostgresPlus\edbmtk\etc\toolkit.properties (Info here):
SRC_DB_URL=jdbc:mysql://SOURCE-HOST-NAME/SOURCE-DB-NAME
SRC_DB_USER=********
SRC_DB_PASSWORD=********
TARGET_DB_URL=jdbc:edb://localhost:5444/DESTINATION-DB-NAME
TARGET_DB_USER=enterprisedb
TARGET_DB_PASSWORD=********
Then: execute C:\Program Files\PostgresPlus\edbmtk\bin\runMTK.bat (Info here).
runMTK.bat -sourcedbtype mysql -targetdbtype enterprisedb -allTables YOUR_DB_SCHEMA
// ...or with a limited subset of tables:
runMTK.bat -sourcedbtype mysql -targetdbtype enterprisedb -tables TABLE1,TABLE2,TABLE3 YOUR_DB_SCHEMA
In order to get this subset of tables from MySQL:
SELECT
GROUP_CONCAT(TABLE_NAME)
FROM
information_schema.tables
WHERE
TABLE_SCHEMA = 'your_db_name'
I downloaded HBase 1.0.1 on my Windows machine and wasn't able to get it to start.
I got the following error message:
C:\Users\admin\Downloads\hbase-1.0.1>bin\start-hbase.cmd
Error: Could not find or load main class " "
ERROR: Could not determine the startup mode.
What's the problem here?
There's a problem in how it is forming the java arguments, specific to the memory options.
Work-around: Find the following line in hbase.cmd and REMOVE %HEAP_SETTINGS%.
set java_arguments=%HBASE_OPTS% -classpath "%CLASSPATH%" %CLASS% %hbase-command-arguments%
I am trying to utilize Jasperstarter with MSSQL on Windows with a JDBC driver. It seems never to find or connect with this driver for some reason despite using the same Driver and URL used by iReport which does work. I can execute reports that do not access the DB, but once I add the database parameters the call fails. I do not get any info back from the call, not sure where the debug stuff goes. Are there any special path settings that need to be made to get this to work? The exec call output just returns a 1 without any failure info.
PHP exec command stream:
"C:\\Inetpub\\wwwroot\\TekEnterpriseServer\\protected\\JasperPHP/JasperStarter/bin/jasperstarter pr ./reports/maintenance.jasper -f pdf -t generic --db-driver net.sourceforge.jtds.jdbc.Driver --db-url jdbc:jtds:sqlserver://localhost/tekenterprise"
The jdbc driver must be put into the jdbc directory of the JasperStarter installation or the path to the driver jar must be specified with --jdbc-dir.
You have to specify username and password as part of the --db-url, see
http://jtds.sourceforge.net/faq.html#urlFormat
You can get verbose output with:
jasperstarter -v pr ./reports/maintenance.jasper ...
I have a SQL script that contains the following
LOAD DATA LOCAL INFILE '.\\datafiles\\customers.txt' INTO TABLE Customers`
I open and run it in MySQL workbench and I get following error:
Error Code: 2. File '.\datafiles\customers.txt' not found
(Errcode: 2 - No such file or directory)
Where should I put file customers.txt according '.\datafiles\customers.txt'?
I use windows 7 and I tried the following placse:
C:\datafiles
C:\temp\datafiles
C:\tem\datafiles
C:\Users\michael\datafiles
I think \\ is incorrect. I Always use full path.
So if the file is in C:\datafiles\ use
LOAD DATA LOCAL INFILE 'C:\datafiles\customers.txt'
INTO TABLE Customers LINES TERMINATED BY '\r\n';
Use absolute path with slash as a separator like this:
'C/your_folder/.../datafiles/customers.txt'
When i execute SQL "LOAD TABLE ...USING CLIENT FILE..." to Sybase IQ database in tomcat's apps,
get this problem"Operation failed on file due to file permissions,hos_clientfileio.cxx 142".
But when i run the piece code in a single java file (not under tomcat), the LOAD TABLE can
succeeded.
what's the cause?
Thanks in advance.
After many tries , i found the problems , i execute the following statement together.
set option allow_read_client_file='ON'
"LOAD TABLE ...USING CLIENT FILE..."
When execute them separatly, the poblem gone.