how to add a txt file into database table in netbeans - sql

i want to add some data's into a table in netbeans. i have the values in .txt and .xls format. is there any way to insert it into the table.?
i found this link to do the work.
Link
but it showed an error when i performed this code
Create or Replace Directory cre_dir as 'C:\Users\Srinivasan\Desktop\SQL';
Error
Error code -1, SQL state 42X01: Syntax error: Encountered "OR" at line 1, column 8.
what is the mistake am i making here..?

You need to grant the CREATE DIRECTORY privilege to the user you are using or the user has to have DBA privilege
The path you are specifying must exists.
Read more about directories here

Related

Problems Loading data from CSV into a PostgreSQL table with PGADMIN

I am at a loss. I am on a mac using PG Admin 4 with PostgreSQL I tried to use the import/export data wizard when you right click on the table I created...and get this error ERROR: extra data after last expected column...all of the colomns match up and there is no additional data. I don't know what needs to change...
So then I tried to create it with the quarry tool with the following code (renaming things to put here):
create schema schema_name;
create table schema_name.tablename( column1 text, column2 text...); ***all the columns are a text data type***
copy schema_name.tablename
from '/Users/me/downloads/filename.csv'
delimiter ',' header csv;
and get this error message:
ERROR: could not open file "/Users/me/downloads/filename.csv" for reading: Permission denied
HINT: COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy.
SQL state: 42501
Going to properties for that database, and then to security, and privileges I made public all privileges. But that did nothing. And so I am here to ask yall for help.
Successfully import the data from the CSV.

Issue storing images in Postges database - permission denied

I have a small database in which I want to store images in a separate table. I have been reading different methods and believe due to the small size of the DB there is no issue in physically storing the image within the DB.
I have been reading and trying to get the sql code correct in order to upload one image into a new table. However I am running into "SQL Error [42501]: ERROR: could not open file.... for reading: Permission denied".
I have tried to change permission access by clicking Command + I on the folder and at the bottom adding "postgres" with "Read & Write" privileges. I closed DBeaver and still not luck.
Is my approach and sql code correct for uploading and image? How do I get around permissions?
create table category (
"id_category" SERIAL,
"category_name" TEXT,
"category_image" bytea,
constraint id_cat_pkey primary key ("id_category"))without oids;
insert into category (category_name,category_image) values('MANGO', pg_read_binary_file('tmp/IMG_2405.jpeg')::bytea)
I was able to upload the image to postgres. I had to move the picture to a folder with in the same directory as postgres. I am still working how to give permission to folders outside of postgres.

SQL syntax error when using Heroku dataclips to export PostgreSQL database into csv

I have a Rails app on Heroku that i'm currently testing to ensure that I can download the information it gathers. I've managed to get PostgreSQL 9.3.5 working and can even get it to spit out a public url to an unreadable dump file, but I want to export a particular table into a CSV that is easier to understand so that I can gather the data.
I've been looking into Heroku Dataclips. The documentation says that this is possible, but doesn't explain how. This site seemed to give some tips on SQL inputs:
http://www.gistutor.com/postgresqlpostgis/10-intermediate-postgresqlpostgis-tutorials/39-how-to-import-or-export-a-csv-file-using-postgresql-copy-to-and-copy-from-queries.html
So I entered this into Dataclips:
COPY participations(user_full_name, user_email, event_name, event_date_time)
TO '/usr/local/pgsql/data/csv/event_registrations.csv'
WITH DELIMITER ‘,’
CSV HEADER
However, I get this error:
Your query couldn't be created.
ERROR: syntax error at or near "COPY"
LINE 2: COPY participation(user_full_name, user_email, event_name, e...
^
How can I fix this? Maybe the reference i'm using is wrong, because I don't see the difference between what i'm doing and what's there.
FWIW, i'm using Cloud9 IDE as my terminal.
If you are trying to get data out in csv file then :
try to do this in command line and put "\" before copy
like this
\COPY participations(user_full_name, user_email, event_name, event_date_time)
TO '/usr/local/pgsql/data/csv/event_registrations.csv'
WITH DELIMITER ‘,’
CSV HEADER
or you can download PGadmin it has option execute query to file under QUERY tab on top
According to Heroku support, this is what you need to put in a Dataclip if you want to get all the records from a particular table:
SELECT * from table_name;
Once you create your Dataclip, you will have the option through the Dataclips interface to download the results as a CSV.

difficulty with the creation of the external table

i have a strange problem with the creation of the external table.
I have an external table "X" under the user X. If i try to create another External Table by doing the copy and paste of sql code, i have this error when i do SELECT * FROM x
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-04040: file CFO_PC.csv in EPM_SERVICE_DATA not found
ORA-06512: at "SYS.ORACLE_LOADER", line 19
the EPM_SERVICE_DATA is the directory where is the file CFO_PC.csv
My user have the grand read and write on this directory.
have you no idea what the problem is?
Sorry for my english...
Is it the same file? CFO_PC.csv Then it should be locked by the original external table.
Copy it, and create a new external table using the copy (make sure that Operating System write/read privileges are correct for the Oracle Database group.
I have resolved, i have copied the sql code from sql developer and it added the code that, it even plays.
LOCATION ( 'CFO_PC.csv' ) is correct
LOCATION ( EPM_SERVICE_DATA: 'CFO_PC.csv' ) not correct

Could not locate entry in sysdatabases for database 'mydb'

I had SQL Server 2005 on my pc and had created a few databases through it. Due to some problem, I had to reinstall it but now when i give the command "create database mydb" it says
"Cannot create file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\myDb.mdf' because it already exists. Change the file path or the file name, and retry the operation."
And when i give "use mydb" command it says
Could not locate entry in sysdatabases for database 'mydb'. No entry found with that name. Make sure that the name is entered correctly.
What should I do so that it can locate my databases?
I faced the same issue.
We need to use Square brackets for database name
ie
use [database]
instead of
use database
Hope it helps.
You can re-attach the database files (assuming that your current installation is at at least the same service pack/patch level as you previously had it).
You can attach the database using either Management Studio, or using CREATE DATABASE
When you re-installed the instance, it won't delete any existing database files and when you are creating a new database its complaining that the file already exists in the default path.
Go to the location C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ and manually delete the myDB.mdf and .ldf files and next go ahead with creating a new database.
HTH
Sometimes I simply just get this issue because I didn't change the primary available database by pressing Ctrl+U into the new DB I created. Often helps to check.