I'm trying to import a CSV table via Netbeans for my Java application.
However, when I try to import values from a CSV file, I get a file type error. It works if I make all the values VARCHARs, but this is inefficient, especially for the short strings of characters that I use.
Here's the CSV file:
GameID,GameName,Developer,Engine,PublishYear,Rating
1,Bioshock Infinite,Irrational Games,Unreal Engine 3,2013,10
2,Hitman: Absolution,IO Interactive,Glacier 2,2012,9
3,Killing Floor,Tripwire Interactive,Unreal Engine 2,2009,7
4,Half-Life 2,Valve,Source,2004,7
5,ESV Skyrim,Bethesda Softworks,Creation Engine,2011,8
6,Batman: Arkham City,Rocksteady Studios,Unreal Engine 3,2011,8
7,Portal 2,Valve,Source,2011,8
8,The Witcher 2,CD Projekt RED,REDengine,2011,9
9,Assassin's Creed 2,Ubisoft,Anvil,2010,8
10,Garry's Mod,Facepunch Studios,Source,2004,6
11,GRID 2,Codemasters,EGO 3.0,2013,7
12,Hotline Miami,Dennaton Games,Game Maker,2012,8
13,Just Cause 2,Avalanche Studios,Avalanche Engine 2.0,2010,7
14,Watch Dogs,Ubisoft,Disrupt,2014,8
15,Deus Ex,Ion Storm,Unreal Engine 1,2000,7
16,Trine 2,Frozenbyte,Proprietary,2011,6
And here's the table creation statement:
CREATE TABLE tblGames (
GameID INTEGER NOT NULL,
GameName VARCHAR(30) NOT NULL,
Developer VARCHAR(30) NOT NULL,
Engine VARCHAR(30) NOT NULL,
PublishYear VARCHAR(20) NOT NULL,
Rating SMALLINT NOT NULL,
PRIMARY KEY (GameID)
);
And here's the import statement:
CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE (
null,
'TBLGAMES',
'D:\OneDrive\Documents\Topic 9\CSV\tblGames.csv',
',', null, null, 0
)
And this is a copy of the error I get:
Error code 30000, SQL state XIE0R: Import error on line 1 of file D:\OneDrive\Documents\Topic 9\CSV\tblGames.csv: Invalid character string format for type INTEGER.
Error code 99999, SQL state 22018: Invalid character string format for type INTEGER.
Now, as I see it, all the GameID values are integers and the ratings are all SMALLINT, so how could there be an error like this?
Related
Table Structure:
CREATE TABLE `cs_menuitem` (
`menuitemid` int(11) NOT NULL AUTO_INCREMENT,
`catid` int(11) DEFAULT NULL,
`itemname` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`menuitemid`),
KEY `fi0` (`catid`)
) ENGINE=InnoDB AUTO_INCREMENT=651879 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='InnoDB free: 9216 kB; (catid) REFER cruzstar_v01/cs_menucate';
Inserted UTF-8 chars using PHP
INSERT INTO `cs_menuitem` (`catid`, `itemname`)
VALUES
(97260, 'as “Sautéed Pastrami” , “Piña Colada Virgin” or “Piña Colada”');
Select query:
SELECT itemname FROM cs_menuitem where menuitemid = 651841;
with the command line, and PHP : (correct result)
as “Sautéed Pastrami” , “Piña Colada Virgin” or “Piña Colada”
But with others (MysqlWorkbench, SequelPro, PhpMyAdmin, PhpStorm, Java), getting: (incorrect result)
as “Sautéed Pastrami†, “Piña Colada Virgin†or “Piña Coladaâ€
I am using Scriptella to copy data from one table to another table(different database) on Mysql. For source, I have used table film from Mysql sample database Sakila.
While copying the data I am getting this error message.
Exception in thread "main" scriptella.execution.EtlExecutorException: Location: /etl/query[1]/script[1]
JDBC provider exception: Unable to get parameter 4
Error codes: [S1009, 0]
Driver exception: java.sql.SQLException: Cannot convert value '2006' from column 4 to TIMESTAMP.
at scriptella.execution.EtlExecutor.execute(EtlExecutor.java:190)
at com.zensar.scrptellaTest.App.main(App.java:21)
Caused by: scriptella.core.ExceptionInterceptor$ExecutionException: /etl/query[1]/script[1] failed: Unable to get parameter 4
at scriptella.core.ExceptionInterceptor.execute(ExceptionInterceptor.java:44)
at scriptella.core.QueryExecutor$QueryCtxDecorator.processRow(QueryExecutor.java:114)
at scriptella.jdbc.StatementWrapper.query(StatementWrapper.java:92)
at scriptella.jdbc.SqlExecutor.statementParsed(SqlExecutor.java:128)
at scriptella.jdbc.SqlParserBase.handleStatement(SqlParserBase.java:129)
at scriptella.jdbc.SqlParserBase.parse(SqlParserBase.java:72)
at scriptella.jdbc.SqlExecutor.execute(SqlExecutor.java:85)
at scriptella.jdbc.JdbcConnection.executeQuery(JdbcConnection.java:222)
at scriptella.core.QueryExecutor.execute(QueryExecutor.java:71)
at scriptella.core.ContentExecutor.execute(ContentExecutor.java:73)
at scriptella.core.ElementInterceptor.executeNext(ElementInterceptor.java:56)
at scriptella.core.StatisticInterceptor.execute(StatisticInterceptor.java:41)
at scriptella.core.ElementInterceptor.executeNext(ElementInterceptor.java:56)
at scriptella.core.ConnectionInterceptor.execute(ConnectionInterceptor.java:36)
at scriptella.core.ElementInterceptor.executeNext(ElementInterceptor.java:56)
at scriptella.core.ExceptionInterceptor.execute(ExceptionInterceptor.java:39)
at scriptella.core.Session.execute(Session.java:103)
at scriptella.execution.EtlExecutor.execute(EtlExecutor.java:227)
at scriptella.execution.EtlExecutor.execute(EtlExecutor.java:183)
... 1 more
This is one row from the table.
'1', 'ACADEMY DINOSAUR', 'A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies', 2006, '1', NULL, '6', '0.99', '86', '20.99', 'PG', 'Deleted Scenes,Behind the Scenes', '2006-02-15 05:03:42'
Here it the DDL statement of both the tables.
sakila.film
CREATE TABLE `film` (
`film_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`description` text,
`release_year` year(4) DEFAULT NULL,
`language_id` tinyint(3) unsigned NOT NULL,
`original_language_id` tinyint(3) unsigned DEFAULT NULL,
`rental_duration` tinyint(3) unsigned NOT NULL DEFAULT '3',
`rental_rate` decimal(4,2) NOT NULL DEFAULT '4.99',
`length` smallint(5) unsigned DEFAULT NULL,
`replacement_cost` decimal(5,2) NOT NULL DEFAULT '19.99',
`rating` enum('G','PG','PG-13','R','NC-17') DEFAULT 'G',
`special_features` set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes') DEFAULT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`film_id`),
KEY `idx_title` (`title`),
KEY `idx_fk_language_id` (`language_id`),
KEY `idx_fk_original_language_id` (`original_language_id`),
CONSTRAINT `fk_film_language` FOREIGN KEY (`language_id`) REFERENCES `language` (`language_id`) ON UPDATE CASCADE,
CONSTRAINT `fk_film_language_original` FOREIGN KEY (`original_language_id`) REFERENCES `language` (`language_id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8;
trg.film
CREATE TABLE `film` (
`film_id` smallint(5) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`description` text,
`release_year` year(4) DEFAULT NULL,
`language_id` tinyint(3) unsigned NOT NULL,
`original_language_id` tinyint(3) unsigned DEFAULT NULL,
`rental_duration` tinyint(3) unsigned NOT NULL DEFAULT '3',
`rental_rate` decimal(4,2) NOT NULL DEFAULT '4.99',
`length` smallint(5) unsigned DEFAULT NULL,
`replacement_cost` decimal(5,2) NOT NULL DEFAULT '19.99',
`rating` enum('G','PG','PG-13','R','NC-17') DEFAULT 'G',
`special_features` set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes') DEFAULT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Scriptella etl.xml
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
<description>Scriptella ETL File Template.</description>
<!-- Connection declarations -->
<connection id="source" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/sakila" user="root" password="12345" />
<connection id="target" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/trg" user="root" password="12345" />
<!-- Uncomment and modify to run a query-based transformation -->
<query connection-id="source">
SELECT * FROM film;
<script connection-id="target">
INSERT INTO film VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13);
</script>
</query>
</etl>
Java Code
public static void main(String[] args) throws EtlExecutorException {
ProgressIndicatorBase indicatorBase = new ProgressIndicatorBase() {
#Override
protected void show(String label, double progress) {
System.out.println(label + "--> " + progress);
}
};
EtlExecutor.newExecutor(new File("etl.xml")).execute(indicatorBase);
}
Please tell me where I am doing wrong or is there any workaround to solve it.
The exception you receive is
Driver exception: java.sql.SQLException: Cannot convert value '2006' from column 4 to TIMESTAMP.
It seems that the particular DB line contains value 2006 in a column where a TIMESTAMP type is expected, the format of which for MySQL seems to be
TIMESTAMP - format: YYYY-MM-DD HH:MI:SS
Ok I think I know.
Just put quotes around the parameter
?4 should look like "?4"
At the source the date is being casted as a string.
So when the insert is created with the string date without the quotes, the date parsing stops after year leaving you with just a number
Hai all I am currently doing a project for a hospital clinical lab. I have come across a problem while fetching data from database. The problem is as follows.
I have 2 category of tests namely Single test and Profile test. The master table of tests contain both the category of tests.
MASTER TABLE of TESTS(LAB_TEST_SERVICES)
CREATE TABLE LAB_TEST_SERVICES (inttestid bigint identity NOT NULL IDENTITY,
testid varchar(15) NOT NULL, testname varchar(255) NOT NULL, cptdesc varchar(300),
splinstr varchar(300), tstabbr varchar(25), reordertime numeric(15),
tstduration numeric(15), autocancel numeric(15), minbiltime numeric(15),
status int NOT NULL, maxbiltime numeric(15), PRIMARY KEY (inttestid));
The type and category of test is stored in following table
LAB_SERVICES_TYPE
CREATE TABLE LAB_SERVICES_TYPE (inttypeid bigint identity NOT NULL IDENTITY,
inttestid bigint NOT NULL, testtype varchar(25), visitype int NOT NULL,
appgendr char(2) NOT NULL, PRIMARY KEY (inttypeid));
If the test comes under single test category, I need to fill the details to the columns of following tables namely LAB_SPECIMEN_MAPPING,LAB_PARAMETER_MAPPING and LAB_TEST_LOCATION.
LAB_SPECIMEN_MAPPING
CREATE TABLE LAB_SPECIMEN_MAPPING (inttestspcid bigint identity NOT NULL IDENTITY,
inttestid bigint NOT NULL, intspcid bigint NOT NULL, intcontid bigint NOT NULL,
volcol numeric(15, 3) NOT NULL, volreq numeric(15, 3) NOT NULL,
status int NOT NULL, PRIMARY KEY (inttestspcid));
LAB_PARAMETER_MAPPING
CREATE TABLE LAB_PARAMETER_MAPPING (intparaid bigint identity NOT NULL IDENTITY,
inttestid bigint NOT NULL, paraname varchar(255) NOT NULL,
parseq numeric(15, 3) NOT NULL, resulttype varchar(30), shortname varchar(30),
mand int NOT NULL, derived int NOT NULL, status int NOT NULL,
PRIMARY KEY (intparaid));
LAB_TEST_LOCATION
CREATE TABLE LAB_TEST_LOCATION (intlocid bigint identity NOT NULL IDENTITY,
intlabid bigint NOT NULL, inttestid bigint NOT NULL, status int NOT NULL,
PRIMARY KEY (intlocid));
And if the test comes under Profile Test category then I need to fill the details to the columns of following table namely LAB_PROFILE_TEST_LIST. Here for each profile test I am mapping a single test to it.
LAB_PROFILE_TEST_LIST
CREATE TABLE LAB_PROFILE_TEST_LIST (intproftestid int identity NOT NULL IDENTITY,
intprotestid int NOT NULL, intsintestid int NOT NULL, PRIMARY KEY (intproftestid));
I had done the following code to find the name of test which is mapped ie for single test if it is mapped then the testid(inttestid from LAB_TEST_SERVICES) will be inserted in LAB_SPECIMEN_MAPPING,LAB_PARAMETER_MAPPING and LAB_TEST_LOCATION or if the test is profile test the testid(inttestid from LAB_TEST_SERVICES) will be inserted in LAB_PROFILE_TEST_LIST.
The tests which is mapped ( both single & profile test).(My contribution to my problem).
SELECT *
FROM LAB_TEST_SERVICES lts
WHERE EXISTS
(SELECT lsm.inttestid
FROM LAB_SPECIMEN_MAPPING lsm
WHERE lsm.status = 1
AND lts.inttestid = lsm.inttestid)
AND EXISTS
(SELECT ltl.inttestid
FROM LAB_TEST_LOCATION ltl
WHERE ltl.status = 1
AND lts.inttestid = ltl.inttestid)
AND EXISTS
(SELECT lptr.intprotestid
FROM LAB_PROFILE_TEST_LIST lptr WHERE lts.inttestid = lptr.intprotestid)
So when I tried to do this no tests appear because I know that there will be no tests having both the characteristics of Single and Profile tests. I had done so many things but cant find a solution. Kindly help me to find out the details tests which is mapped both single and profile.I am using Java, Hibernate and SQL SERVER. Thanks in advance
This is how I tried to create table:
CREATE TABLE namevalues
(
seqid integer NOT NULL,
name text(50) NOT NULL,
value text(50),
CONSTRAINT namevalues_pkey PRIMARY KEY (seqid, name)
);
I tried doing this but this doesn't work. could anyone please tell how should I specify the length?
The TEXT type in PostgreSQL does not have a size. You can fix it like this:
CREATE TABLE namevalues
(
seqid integer NOT NULL,
name text NOT NULL,
value text,
CONSTRAINT namevalues_pkey PRIMARY KEY (seqid, name)
);
or use VARCHAR(50) instead of TEXT.
Don't use text, you want varchar...
CREATE TABLE namevalues
(
seqid integer NOT NULL,
name varchar(50) NOT NULL,
value varchar(50),
CONSTRAINT namevalues_pkey PRIMARY KEY (seqid, name)
);
From the PostgreSQL docs...
text: variable unlimited length
Use varchar(50) instead of text(50).
Because,
PostgreSQL API says text data type does't have size, it allow variable with unlimited length
CREATE TABLE namevalues
(
seqid integer NOT NULL,
name varchar(50) NOT NULL,
value varchar(50),
CONSTRAINT namevalues_pkey PRIMARY KEY (seqid, name)
);
Reference
I am using eclipse and following http://www.eclipse.org/articles/article.php?file=Article-EclipseDbWebapps/index.html and it all works fine except when I try to run my own sql code.
Here it is:
CREATE TABLE honscores (
idhonscores INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
Name varchar(25) NOT NULL,
Characters VARCHAR(25) NOT NULL,
Kills integer(11) NOT NULL,
Deaths integer(11) NOT NULL,
Assists integer(11) NOT NULL,
XPM integer(11) NOT NULL,
CK integer(11) NOT NULL);
Any help will be appreciated.
Here is the error message :
Syntax error: Encountered "(" at line 5, column 20.
Elapsed Time: 0 hr, 0 min, 0 sec, 0 ms.
CREATE TABLE app.honscores ( //schema name is before the table name
idhonscores INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
Name varchar(25) NOT NULL,
Characters VARCHAR(25) NOT NULL,
Kills integer NOT NULL,
Deaths integer NOT NULL,
Assists integer NOT NULL,
XPM integer NOT NULL,
CK integer NOT NULL
);
Im pretty sure this is how I fixed it