I exported a java project as a jar in windows and uploaded the jar to a linux server. On executing the jar I get to see "C:" being appended in the beginning of the file path. Here's the log :
Query : LOAD data infile "/home/user/java_correlation_engine/CorrelationFiles/temp.txt" ignore into table logical_mapping fields terminated by '|' lines terminated by '\n'
java.sql.SQLException: File 'C:\home\user\java_correlation_engine\CorrelationFiles\temp.txt' not found (Errcode: 2 - No such file or directory)
The query looks exactly how I wanted it to be but it throws SQLException.
Related
Try to insert file to existing local folder. But seems like there's any security or permission issue
String path = con.getConfigValue("CustomPathImgUpload"); //return /Users/name/Documents/
File file = new File(path + date + "_" + fileName);
Got error below
java.io.FileNotFoundException: /Users/name/Documents/20221010_abc.xlsx (No
such file or directory) at
java.base/java.io.FileInputStream.open0(Native Method) at
java.base/java.io.FileInputStream.open(FileInputStream.java:211)
Check users folder , system read write
check name folder , name read write
check documetns folder, name read write
Eclipse apps and chrome apps already get full disk access
Get this problem after update from OS bigsur to menterey
How to solve this issue?
EDIT
Try to change the path to /Users/ and /Applications/ still folder location not found.
Make sure it's not source code mistakes by run it in windows eclipse. File saved correctly
ada usr/bin/java , jawaw, javap, etc to full disk access still not work
EDIT 2
try to use System.getProperty("user.home") + File.seperator + date + filename
return "/Users/name/20221010_abc.xlsx" But still get no such directory :'(
Is it because my Users folder permission looks like this?
OR is there any way to check what path is exist ?
How do I insert a file that resides in windows in c:\temp\sample.txt
I have tried
insert into lob_file VALUES (5, pg_read_file('c://temp//sample.txt')::BYTEA);
and got
ERROR: could not start file c://temp//sample.txt. No such file or
directory.
Is data base running locally or on a Windows server and you have moved the file to the server. See Docs
The functions shown in Table 9.94 provide native access to files on
the machine hosting the server. Only files within the database cluster
directory and the log_directory can be accessed unless the user is
granted the role pg_read_server_files. Use a relative path for files
in the cluster directory, and a path matching the log_directory
configuration setting for log files.
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.
I am new in Hsqldb database. I want to know how to take backup and restore of Hsqldb database through java code.
Use the BACKUP DATABASE TO command.
Here is a link to the documentation:
HSQLDB System Management Documentation
I haven't tested this, but I imagine it's something along the lines of:
String backup = "BACKUP DATABASE TO " + "'" + filePath + "' BLOCKING";
PreparedStatement preparedStatement = connection.prepareStatement(backup);
preparedStatement.execute();
You'll want to wrap it in a try-catch block of course.
As far as restoring the db goes, I think you have to perform that while the database is offline using the DbBackupMain application. So you would issue this command at the command line:
java -cp hsqldb.jar org.hsqldb.lib.tar.DbBackupMain --extract tardir/backup.tar dbdir
Each HyperSQL database is called a catalog. There are three types of catalog depending on how the data is stored.
Types of catalog data :
mem: stored entirely in RAM - without any persistence beyond the JVM process's life
file: stored in filesystem files
res: stored in a Java resource, such as a Jar and always read-only
To back up a running catalog, obtain a JDBC connection and issue a BACKUP DATABASE command in SQL. In its most simple form, the command format below will backup the database as a single .tar.gz file to the given directory.
BACKUP DATABASE TO <directory name> BLOCKING [ AS FILES ]
The directory name must end with a slash to distinguish it as a directory, and the whole string must be in single quotes like so: 'subdir/nesteddir/'.
To back up an offline catalog, the catalog must be in shut down state. You will run a Java command like
java -cp hsqldb.jar org.hsqldb.lib.tar.DbBackupMain --save tardir/backup.tar dbdir/dbname
. In this example, the database is named dbname and is in the dbdir directory. The backup is saved to a file named backup.tar in the tardir directory.
where tardir/backup.tar is a file path to the *.tar or *.tar.gz file to be created in your file system, and dbdir/dbname is the file path to the catalog file base name.
You use DbBackup on your operating system command line to restore a catalog from a backup.
java -cp hsqldb.jar org.hsqldb.lib.tar.DbBackupMain --extract tardir/backup.tar dbdir
where tardir/backup.tar is a file path to the *.tar or *.tar.gz file to be read, and dbdir is the target directory to extract the catalog files into. Note that dbdir specifies a directory path, without the catalog file base name. The files will be created with the names stored in the tar file.
For more details refer
So in java + SPring + JdbcTemplate
Backup (On-line):
#Autowired
public JdbcTemplate jdbcTemplate;
public void mainBackupAndRestore() throws IOException {
...
jdbcTemplate.execute("BACKUP DATABASE TO '" + sourceFile.getAbsolutePath() + "' BLOCKING");
}
This will save .properties, .scripts and .lobs file to a tar in sourceFile.getAbsolutePath().
Restore:
DbBackupMain.main(new String[] { "--extract", baseDir.getAbsolutePath(),
System.getProperty("user.home") + "/restoreFolder" });
This will get files from baseDir.getAbsolutePath() and will put them in userHome/restoreFolder where you can check if all restore is OK.
lobs contains lob/blob data, scripts contains executed queries.
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'