Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

mysql - columns not found by java mariadb connection

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...