I have just started using MySQL today, so please without hate.
This is the table how it looks in phpmyadmin: http://i.imgur.com/B6wg9qG.png
Here is the method I'm using: http://i.imgur.com/BZWhZw9.png
Here is the error I'm getting: "Bad format for number 'gold' in column 1.", it's pointing on this line: return st.getDouble(1);
Thanks for any help!
You're doing
SELECT 'gold' FROM `Economy` WHERE...
That will select the string literal 'gold' from the database, not the value of the gold field.
If you want to quote a field name, you need to use backticks;
SELECT `gold` FROM `Economy` WHERE...
...although the query in this case will work just as well without quoting the field name at all.
Related
I'm getting below error while executing the following query using JPA native query
Error :
ERROR: operator does not exist: record = character varying
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 228
Query:
select ar.adm_rule_id
from adm_promo.adm_rule ar,
adm_promo.adm_non_comp_rule ac,
adm_promo.adm_rule_hier_level ah
where ar.rule_type =?
and ar.sales_org_id=?
and (ac.promo_market_id,ah.level_id) in (?)
and ar.adm_rule_id=ac.adm_rule_id
and ar.adm_rule_id=ah.adm_rule_id
and ar.delete_f='N'
and (ar.eff_end_date>=(?) and ar.eff_start_date<=(?))
and ar.dist_channel=?
But I'm getting result for the same query with actual inputs, when I tried in PostgreSql
Query with inputs:
select ar.adm_rule_id
from adm_promo.adm_rule ar,
adm_promo.adm_non_comp_rule ac,
adm_promo.adm_rule_hier_level ah
where ar.rule_type =1
and ar.sales_org_id=1
and (ac.promo_market_id,ah.level_id) in ((9,63))
and ar.adm_rule_id=ac.adm_rule_id
and ar.adm_rule_id=ah.adm_rule_id
and ar.delete_f='N'
and (ar.eff_end_date>=('2020-09-29')
and ar.eff_start_date<=('2020-10-17'))
and ar.dist_channel=1
I couldn't find the issue exactly, team please help me to resolve this issue.
I suspect it has a problem with this:
(ac.promo_market_id,ah.level_id) in (?)
Try to cast it, as suggested in the error, by changing the query to:
(ac.promo_market_id,ah.level_id) in (?::record)
Judging by the fact that it says "position 228" and scrolling along to that character of your query puts you near this:
(ac.promo_market_id,ah.level_id) in ((9,63))
but your template for the query has this
(ac.promo_market_id,ah.level_id) in (?)
It might well be that you are providing the wrong sort of data there. It is unlikely that your database driver supports parameterized lists of values (to match your "IN" clause). You are probably ending up with some quoted text, which Postgres is treating as "character varying" which of course fails to match.
I created a page to insert and modify data of an existing mysql- table.
But based on my requirements and the structure of the table I have to modify the sql for inserting data.
Because I am completly new on rapidclipse and java I need some hints/ examples how and where to modify this.
Looking all rapidclipse videos did not give the right hint.
I would like to insert three fields into a mysql-table
One of the fields I have to edit manualy.
The second field contains always the same value.
The third field contains a calculated value, which I have to fetch while runtime from the database.
As sql I would use following code:
INSERT INTO OKM_DB_METADATA_VALUE (DMV_TABLE, DMV_COL00, DMV_COL01)
VALUES ('T_supplier', (select * from (select max(cast(DMV_COL00 as
Integer)) +1 from OKM_DB_METADATA_VALUE as t2 where DMV_TABLE =
'T_supplier') as t3 ) , 'new suppliername');
The value for field DMV_Table will be always 'T_supplier'
The value for field DMV_COL00 is always the highest value in the col +1
The value for field DMV_COL01 will be always entered manually
(I am not able/ I don't want to modify/ use table form, -design and trigger, because it is a original table of OpenKM)
Thank you in advance!
best regards
OpaHeinz
Just a suggestion for sql code .. Your code could be refactored in a more SQL like code .. You could avoid the innner subquery .. and use a normal insert select
INSERT INTO OKM_DB_METADATA_VALUE (DMV_TABLE, DMV_COL00, DMV_COL01)
select 'T_supplier', max(cast(DMV_COL00 asInteger)) +1 , 'new suppliername'
from OKM_DB_METADATA_VALUE
where DMV_TABLE ='T_supplier'
The first step to solution
In the buttonClick event of save function
I set the value of DMV_Table field with:
... this.txtDmvTable.setValue("T_supplier");
The second step;
I created a view in the database wich delivers only the expected value:
`CREATE
OR REPLACE
VIEW `okmdb`.`V_suppliers_newID` AS
select
1 as "id",
max(cast(DMV_COL00 as Integer)) +1 as "newSupId"
from OKM_DB_METADATA_VALUE
where DMV_TABLE = 'T_supplier'; `
After that I created an entity in rapidclipse, read the value out of the view and assigned it to the other field DMV_COL00.
This was all.
I am dealing with a database that has column with spaces. So I try to enclose the Column in brackets like this...
#Column(name = "[Licensee Address]")
However when I run the app. Hibernate replaces Brackets with this
`Licensee Address`
Which throws a error
Incorrect syntax near '`'.
MSSQL uses brackets not quotes. How do I fix this ??
When I do it without the brackets it generates the following sql...
Hibernate: select licenseein0_.WRRAppID as WRRAppID1_1_0_, licenseein0_.ApplicantTypeID as Applican2_1_0_, licenseein0_.BusinessActivity as Business3_1_0_, licenseein0_.CompanyID as CompanyI4_1_0_, licenseein0_.CreatedBy as CreatedB5_1_0_, licenseein0_.CreatedDate as CreatedD6_1_0_, licenseein0_.DBAName as DBAName7_1_0_, licenseein0_.FCCCallSign as FCCCallS8_1_0_, licenseein0_.FCCFileNumber as FCCFileN9_1_0_, licenseein0_.FCCRegistration# as FCCRegi10_1_0_, licenseein0_.FedTaxID# as FedTaxI11_1_0_, licenseein0_.LicenseActionID as License12_1_0_, licenseein0_.LicenseeName as License13_1_0_, licenseein0_.RadioService as RadioSe14_1_0_, licenseein0_.RadioUse as RadioUs15_1_0_, licenseein0_.SubmittedDate as Submitt16_1_0_ from Licensee_Information licenseein0_ where licenseein0_.WRRAppID=?
And the error message I get is...
Incorrect syntax near the keyword 'as'.
Figured it out. Had to incorrect hibernate dialect set up. It must be the following
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.SQLServerDialect
The column name isn't [Licensee Address], the column name is Licensee Address. If you remove the [ and ] it should work. If you are writing a query in T-SQL and you need to reference a column named with a space, special characters or reserved words, you need to put the [ and ] so the query parser knows where the column name starts and stops. But you are not writing T-SQL, so you don't need to do that.
I am trying to develop a inventory management system as part of my mini project.
While I try to Insert a data to my Bill_Master Database it returning an error
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-01858: a non-numeric character was found where a numeric was expected
bqty=Integer.parseInt(iqty.getText());
bamount=Float.parseFloat(famnt.getText());
bdsc=Integer.parseInt(dsc.getText());
bnet=Float.parseFloat(netamnt.getText());
billid=Integer.parseInt(billn.getText());
code=Integer.parseInt(icode.getText());
bqty=Integer.parseInt(iqty.getText());
rate=getRate(code);
iamount=rate*bqty;
amt.setText(Float.toString(iamount));
total=total+iamount;
try
{
billdetailid++;
stmt.executeUpdate("insert into Bill_Master values('"+billid+"','"+date+"','"+cname+"','"+total+"','"+bdsc+"','"+total+"','"+uid+"')");//Error Causing Line.
Values are
(1,'27-oct-2013','n/a',900.00,0.0,900.00,'Desk')
Table Structure
Bill_Id (Primary Key INT ):-Stores Bill Number
Bill_Date (Date): Stores Date Of Bill
Customer_Name ( VARCHAR(50)): Customer Name
Total_amt (NUMBER(6)) :Total Bill Amount
Cash_Disc (Number(2)):Discount
Grand_Total(Number(6)):Grand Total
UID(VARCHAR(10)) Stores Who Generated the bill.(EMPLOYEE ID)
Connection Type :ODBC
Please help to solve this issue.
You are putting single quotes around each of your values including bill_Id which is defined as an int. the SQL database is reading this as a string and complaining. Also (as was already pointed out) PreparedStatements make this a lot easier and more secure.
Try this:
stmt.executeUpdate("insert into Bill_Master values('"+billid+"',to_date('"+date+"', 'dd-MON-yyyy'),'"+cname+"','"+total+"','"+bdsc+"','"+total+"','"+uid+"')");
Firstly that is one horrible way of writing SQL queries in java !!!
I am guessing you have just started learning. Please check out PreparedStatements
Data Type related bugs will become easier to debug.
Also that is not the way you write continuous string appends. Check out StringBuilder and String Buffer
I found the exact problem. The reason was I am trying to insert the Label instead of the text in the label.
correct statement is
stmt.executeUpdate("insert into Bill_Master values('"+billid+"','"+date.getText()+"','"+cname.getText()+"','"+total+"','"+bdsc+"','"+total+"','"+uid+"')");
I have the following SQL that returns the max BILL_DATE based on some criteria. BILL_DATE is defined in the database as a DATE.
SELECT MAX(BILL_DATE)
FROM BILLTABLE
WHERE col1 = ? and
col2 = ?
But when I read the value from the resultSet.
bill.setBillDate(resultSet.getDate(1));
An exception is thrown:
Invalid data conversion: Wrong result column type for requested conversion. ERRORCODE=-4461, SQLSTATE=42815
I have also tried
bill.setBillDate(resultSet.getString(1));
But that doesn't return a date. It returns either 100, 200 or 300 which is obviously not correct.
Is there another way to do this? Am I doing something wrong?
Ash is right, how are you defining the date column?
Is it possible the column is timestamp? In that case try resultSet.getTimestamp(1))
I had two resultSets open in the function where I was reading in the BILL_DATE. I changed the code to the following and it works fine.
bill.setBillDate(resultSet1.getDate(1));