HSQLDB select shows no data in intellij IDEA - intellij-idea

i have created and rund successul this sql using HSSQLDB (Connection type Embedded) :
CREATE TABLE IF NOT EXISTS PUBLIC.T1 (name CHAR(25), age INTEGER NOT NULL);
insert into T1 (name, age) values ('lise',99);
insert into T1 (name, age) values ('fred',199);
insert into T1 (name, age) values ('paul',299);
select * from PUBLIC.T1;
i'm used to doing a select in jetbrains idea so that i can see the data.
Here with (HSSQLDB Connection type: Embedded) no data is shown to me (scceenshow below).
Are there none or how can I see them?
Connection type with this HSSQLDB is Embedded as you could see in the screeshot below:
Connection type: Embedded
comparision with sqLite (no problems):
Since I still have the problem that with hssqldb no data is displayed via the IDEA database window, I have tried SqLite once and it does not cause any problems at all (see Screenshot):
comparision with HSSQLDB file (no problems):

As #eh3rrera explains here https://github.com/eh3rrera/minitwit/issues/11#issuecomment-795467775:
"... I'm not sure if IntelliJ can access it, I think it can only be accessed by the Java program that created it.
Unlike an in-memory db, with db in a file, changes are persisted after the app exits, they're saved to the file. ..."

Related

Import Excel Data Into Temporary Table Without Using OLEDB in SQL Server

I am trying to look for a way to import excel data into a temporary table without using OLEDB since I don't have OLEDB installed in SQL Server and I can not install it due to security restrictions.
I am aware of below mentioned ways of doing it but this is not going to help me
Begin Tran
If OBJECT_ID('tempdb..#tblUserImport') IS NOT NULL
Begin
Drop table #tblUserImport
end
Create Table [dbo].[#tblUserImport]
(
id nvarchar(max) NULL,
Name nvarchar(max) NULL,
Job_Title nvarchar(max) NULL,
Work_Email nvarchar(max) NULL
)
INSERT INTO [dbo].[#tblUserImport]
SELECT id, Name, Job Title, Work Email
FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel12.0;HDR=YES;Database=C:\Users\Desktop\Book2.xlsx', 'SELECT * FROM [Sheet1$]');
select * from [#tblUserImport]
Rollback Tran
I will get the below mentioned error if I execute the openrowset.
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered.
Is it possible to achieve it using Stored Procedure or any other way?
Here are 3 options:
1.Do the import from a computer you have admin rights on
It sounds like you don't have the ability to install OLE or ODBC data providers on the SQL Server machine. But you don't have to run the import from the same machine. As long as you have valid credentials and a working network path to your SQL server, you can run the import from any computer. So you could install the Microsoft ACE OLEDB 12.0 data provider driver on another PC along with SQL Server Management Studio, copy the Excel file there, and then do the import through the wizard.
Try an alternate data provider driver
There are alternate data provider drivers for Excel sources that may already be installed in your environment. E.g. the Jet OLEDB 4.0 driver mentioned at https://www.connectionstrings.com/excel/. Connection string:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;
Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";
Use Excel formulas to build INSERT statements
You can use the venerable Excel formula trick alluded to in RBell's answer: Assuming the fields you specified in your question are in A1 through D1, add this formula to cell E1:
="INSERT INTO #tblUserImport VALUES ('"&SUBSTITUTE(A1, "'", "''")&"', '"&SUBSTITUTE(B1, "'", "''")&"', '"&SUBSTITUTE(C1, "'", "''")&"', '"&SUBSTITUTE(D1, "'", "''")&"');"
You then copy this formula down through all rows of your data. Excel will automatically alter the cell references for each row. Note that the SUBSTITUTE() function handles single-quotes in the data that might otherwise break the SQL syntax. Then you simply copy and paste the resulting text out into your SQL window, and run it.
super mcguyver way using table variables. use the concat function on your excel sheet to prepare the data for the insert part.
declare #temp1 table (id int identity(1,1),name varchar(255),job_title varchar(255),work_title varchar(255),work_email varchar(255));
insert into #temp1 (name,job_title,work_title,work_email)
values
('John','Electrician','level 3 lightning wizard','john#ex.com'),
('amy','Java Developer','Cyber Coffee Slinger','amy#ex.com');
Its quite a bit of work , but feasible
I am assuming you have read-only access to prod db with temp table creation and insert into temp table statements.
No access to sql wizards or any elevated privileges.
Below 4 steps we have to preform in our dev sql box. Then generate the create #temptable script and auto generated insert statements and run them in production temp database
save the excel as csv file to dev machine
create a #temptable/ ##temptable ( because usually developers wont have create table permissions in production database )
Note : if the table has more columns use wizard to generate the auto crate table statement.
How ?
Answer is : Right click on Database --> Task --> Import Data --> on sql server import and export wizard, select the data source as flat file source and browse the csv file what you created in step1. --> Next --> on the choose a destination select destination as sql server native client 11.0 --> next --> on select source table and views screen choose edit mappings --> on column mappings screen click edit sql button which gives auto generated create table statement.
Copy the auto generated script --> edit the name to ##TempTable_CSV --> Create the temp table.
Now table is ready. For data ,
Use Bulk insert by giving the csv path
BULK INSERT ##TempTable_CSV
FROM 'C:\Users<username>\Downloads\temp.csv'
WITH ( FIRSTROW = 2, FORMAT = 'CSV');
To auto generate the insert statements from the temp table ( for example assuming the temp table has id , varchar columns )
select 'insert ##TempTable_CSV values ('+Cast(Id as varchar(5))+','''+SomeVarcharColumn+''') from ##TempTable_CSV
which will generate all the insert into statements
Note : Make sure to handle null values
Finally you can copy the create temp table script from step 2 + auto generated insert statements from step 4 , run it in prod temp db.
Enjoy :-)

Link object is not supported on free connection using Advantage Database

I'm developing a program using vb.net under VS2017 and ADS v11.1 on Visual Foxpro free tables with adsDataAdapter.
I want to copy records from a current table into a history table:
INSERT INTO
c:\data\hinv.dbf
SELECT
*
FROM c:\data\cinv.dbf WHERE [balance] = 0.00
I get the error:
The requested object was not found. c:\data\hinv Link object is not supported on free connection. Table name: dbf
The connection string includes
Data Source: c:\data\; TableType=VFP; LockMode=COMPATIBLE; ServerType=LOCAL
The connection works perfectly for SELECT, INSERT, DELETE and UPDATE commands not using a subquery, for example
INSERT INTO
c:\data\hinv.dbf
(
[field1]
, [field2]
)
VALUES
(
value1
, value2
)
will work with no problem. I've tried the SAP community but received no response, and I've searched the net every way I can think of. I'm stumped.
ADS is confused by the dot notation of the table you are selecting from.
Here is a similar post:
http://devzone.advantagedatabase.com/forum/questions/3294/sql-selection-from-dbf
ADS thinks you are selection from a table named dbf on a server link named c:\data\hinv.
You probably have to set the table type from VFP to CDX for ADS to recognize the filename as a table name.

Invalid object name 'PetDatabase.Sales'

Im trying to run the following to import a large volume of sales data in a text file into a database. When i run the following i get the error: "Invalid object name 'PetDatabase.Sales'
BULK INSERT PetDatabase.Sales
FROM 'C:\Temp\P1.txt'
WITH
(
FORMATFILE = 'C:\Temp\PetSales.Fmt'
);
Can anyone see whats causing my problem? I do have the tables within a folder; however, when i tried PetsDatabase.Tables.Sales it made no difference.
Ignore this answer. It was written when the question was tagged with mysql. Leaving the answer here to keep the comments.
--
Try using LOAD DATA INFILE instead.
http://dev.mysql.com/doc/refman/5.1/en/load-data.html
Make sure PetDatabase.Sales exists in your text file.
Swap for whichever row and field terminator delimiters you're using. Here I'm using delimiters from a comma separated file
BULK INSERT PetDatabase
FROM 'c:\temp\p1.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
--Check the content of the table.
SELECT *
FROM PetDatabase
GO
--Drop the table to clean up database.
SELECT *
FROM PetDatabase
GO
Also, make sure the following doesn't apply to you:
If a SQL Server user is logged in using Windows Authentication, the user can read only the files accessible to the user account, independent of the security profile of the SQL Server process.
When executing the BULK INSERT statement by using sqlcmd or osql, from one computer, inserting data into SQL Server on a second computer, and specifying a data_file on third computer by using a UNC path, you may receive a 4861 error.
To resolve this error, use SQL Server Authentication and specify a SQL Server login that uses the security profile of the SQL Server process account, or configure Windows to enable security account delegation.
Is PetDatabase is schema name or database name?
If it is database name, then include schema name also like this if your schema name is dbo.
PetDatabase.dbo.Sales

How to insert the contents of a text file into a table in SQL Server

I have several files (they are XML but that's not important) that need to be inserted into an existing SQL table (i.e. I didn't design it.) The table looks like this.
ReportType
ID (int) <- identity
Name (varchar(32))
TransformXSLT (nvarchar(max))
Normally I would do:
INSERT INTO ReportType (Name, TransformXSLT)
VALUES ('template name', '<lots><of><xml><goes><here>...</lots>')
Is there any way to do:
INSERT INTO ReportType (Name, TransformXSLT)
VALUES ('template name', {filename})
I'm using SQL Server Management Studio and Eclipse+Maven to manage the files.
BULK INSERT or OPENROWSET(BULKā€¦) are the usual options from T-SQL
After comment...
...FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB);
and the "Bulk Exporting or Importing SQLXML Documents" section here
Sorry, I've not actually tried this but MSDN says you can
Have you tried using the SQL Server Import and Export Wizard?
Go into SQL Server Management Studio. In Object Explorer, right click the database then Tasks > Import Data....
This will let you import data as a one off exercise, or let you save the resulting SSIS package and re-run it.
Give it a go.

copying a table from one database to another

I am trying to archive some of my tables into another database on the same server. However the INSERT INTO...SELECT...FROM gives me an error (SQLSTATE=42704) on build. The table exists in the second database.
Can anyone help with this?
It's not clear from your question what version of DB2 is being used. I'll presume that it's the Linux, Unix & Windows version. You look to be using federation to link the two databases.
Does the SELECT part of your query work from LS2DB001? It's worth trying to pin down which database you have the issue with.
Presuming that the problem is on LS2DB001, if the user you have defined the federated link with has permissions on the base tables in the query, check also that they have permissions on the system catalog tables. If not, they would not be able to parse and validate that you can run the query.
We've cracked it! If the following script is used then it works. The LOAD works without having to COMMIT in between batches of rows copied. ('Transaction Log full...' error problem is also solved)
CONNECT TO LS2DB001;
EXPORT TO "C:\temp\TIN_TRIGGER_OUT.IXF" OF IXF
MESSAGES "C:\temp\TIN_TRIGGER_OUT.EXM"
SELECT * FROM LS2USER.TIN_TRIGGER_OUT;
CONNECT RESET;
CONNECT TO LQIFCOLD;
LOAD FROM "C:\temp\TIN_TRIGGER_OUT.IXF" OF IXF
MESSAGES "C:\temp\TIN_TRIGGER_OUT.IMM"
INSERT INTO LS2USER.TIN_TRIGGER_OUT COPY NO INDEXING MODE AUTOSELECT;
COMMIT;
CONNECT RESET;
I found this on http://www.connx.com/products/connx/Connx%208.6%20UserGuide/CONNXCDD32D/DB2_SQL_States.htm:
42704 Undefined object or constraint name. Revise SQL syntax and retry.
For more help try to be more specific, eg paste the full sql statement, the table scheme etc.
You can do
Select 'insert into tblxxxx (blabla,blabal) values(' + fld1 + ',' + fld2 + ',' ...... + ')'
From tblxxxxxx
copy the result as a text script and execute it in the other DB.
The best way to do this would be to create a custom script. Depending on the size of the tables (how many records) you could either do a select of all of the data into memory and then roll over them inserting them into a copy of the table you create first, or you could export the data out as a csv file or some other text based file and then roll over that to insert the data into the other table.
If you do not have some sort of formal backup procedures that could do this already, this would be your best bet.
Note: some db2 databases, such as those on an iSeries do not actually have "databases", they have libraries. With the right user profile you can access two libraries at the same time, joining tables from them together or doing a
create table library/newFilename as
(select * from originallibrary/originalfilename) with data
But this only applies to the iSeries I believe.
I'm writing this response as another answer so I have more space.
I can only suggest breaking the steps down to their components, and working through to see where the error is occuring. Again, I'm assuming you're using federation:
a) In your FROM db, connecting as the user you're using for the federated link, does your select work?
b) In your TO db, using the link, does the select work?
c) In your TO db, using the link via a stored proc, does the select work?
d) In your TO db, using an INSERT...values(x,y,z), can you insert into the table?
e) In your TO db, via a stored proc, using INSERT...values(x,y,z), can you insert?
Without more information, this is the best line of attack I can suggest.