i'm using java to insert some data into a mariadb database, but when i execute the statement, i receive an error
Unknown column 'SCHEDETYPE' in 'field list'
java.sql.SQLSyntaxErrorException: (conn=84) Unknown column 'SCHEDETYPE' in 'field list'
but in my db the columns exists.
i tried to extract the column names through this code:
ResultSetMetaData rsMetaData = rs.getMetaData();
int numberOfColumns = rsMetaData.getColumnCount();
// get the column names; column indexes start from 1
for (int i = 1; i < numberOfColumns + 1; i++) {
String columnName = rsMetaData.getColumnName(i);
// Get the name of the column's table name
String tableName = rsMetaData.getTableName(i);
System.out.println("column name=" + columnName + " table=" + tableName + "");
}
but i'm returning only 6 columns from db
column name=id
column name=label
column name=user_id
column name=submitted
column name=created_at
column name=updated_at
where is the problem??
thank you
my query
final String query = "INSERT INTO test.sc_test "
+ "(LABEL, SCHEDETYPE,SCHEDECURRENT,user_id,submitted,is_hibernated,bad_formed,is_valid,"
+ "start_hibernation,namespaces,created_at,updated_at) "
+ "VALUES(?,?,?,?,null,0,?,?,365,?,?,null)";
java.sql.PreparedStatement prest = con.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
prest.setString(1, cst.getLabel());
prest.setString(2, cst.getSchedeType());
prest.setString(3, cst.getSchedeCurrent());
prest.setInt(4, cst.getUser_id());
prest.setInt(5, cst.getBad_formed());
prest.setInt(6, cst.getIs_valid());
prest.setString(7, namespaces);
prest.setTimestamp(8, ts);
prest.executeUpdate();
from db
field,type,null,key,default,extra
'id', 'int(11) unsigned', 'NO', 'PRI', NULL, 'auto_increment'
'label', 'varchar(100)', 'NO', '', NULL, ''
'SchedeType', 'varchar(45)', 'YES', '', NULL, ''
'SchedeCurrent', 'varchar(100)', 'YES', '', NULL, ''
'user_id', 'int(11)', 'YES', '', NULL, ''
'submitted', 'timestamp', 'YES', '', NULL, ''
'is_hibernated', 'int(1)', 'NO', '', '0', ''
'bad_formed', 'int(1)', 'NO', '', '0', ''
'is_valid', 'int(1)', 'NO', '', '0', ''
'start_hibernation', 'int(4)', 'NO', '', '365', ''
'namespaces', 'varchar(100)', 'NO', '', 'gml,xsi,xlink', ''
'created_at', 'timestamp', 'YES', '', 'current_timestamp()', ''
'updated_at', 'timestamp', 'YES', '', NULL, ''
question from:
https://stackoverflow.com/questions/66048763/columns-not-found-by-java-mariadb-connection