简体   繁体   English

java.sql.SQLSyntaxErrorException:ORA-00928:缺少SELECT关键字

[英]java.sql.SQLSyntaxErrorException: ORA-00928: missing SELECT keyword

I get this error when i was inserting some rows to database. 当我向数据库中插入一些行时出现此错误。

Code

public class InsertRowData {
    public static void main(String[] args)throws ClassNotFoundException, SQLException{

        Connection con = (Connection) DriverManager
                 .getConnection("jdbc:oracle:thin:@localhost:1521:ORCL" , "system" , "system");

        Statement statement = con.createStatement();
        String dmlinsert = "insert into student(111,manoj,rawatrulz09)";

        int rowseffected = statement.executeUpdate(dmlinsert);      
        System.out.println("no of rows effected" + rowseffected);

    }   
}

After searching in google I found the solution to remove single quotes from the column but still getting the same error. 在谷歌搜索后,我找到了从列中删除单引号的解决方案,但仍然遇到相同的错误。 ps-I am a newbie ps-我是新手

This is a bad approach to insert any data into the Table. 将任何数据插入表中都是一种不好的方法。

String dmlinsert="insert into student(111,manoj,rawatrulz09)"

first of all, your query missing a syntax Values . 首先,您的查询缺少语法Values

when columns are not mentioned while inserting, values must contain same amount of data and respectively. 如果在插入时未提及列,则values必须分别包含和相同的数据量。

But when inserting a data the best practice is to mention columns, so that if in later time you make any change to the table in database, your insert query stays stable. 但是,在插入数据时,最佳实践是提及列,以便以后在数据库中对表进行任何更改时,插入查询都保持稳定。 for eg: insert into student(id, name, email) values(111,'manoj','rawatrulz09') . 例如: insert into student(id, name, email) values(111,'manoj','rawatrulz09')

Now, if in future you will add a column to this table, your insert query will still work as it has mentioned columns, but if you won't mention any columns then your code will start giving error when executed no of values don't match given to the table etc... Good luck! 现在,如果将来要在此表中添加一列,则插入查询仍将按其提到的列继续工作,但是如果您不提及任何列,则执行代码时如果no of values don't match given to the table则代码将开始出错no of values don't match given to the table等...祝你好运! anyway, answer for your insert query: 无论如何,回答您的插入查询:

insert into student values(111,'manoj','rawatrulz09')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从多个表中删除记录时获取“ java.sql.SQLSyntaxErrorException:ORA-00928:缺少SELECT关键字” - Getting “java.sql.SQLSyntaxErrorException: ORA-00928: missing SELECT keyword” on deleting Record from multiple tables java.sql.SQLException:ORA-00928:缺少SELECT关键字 - java.sql.SQLException: ORA-00928: missing SELECT keyword ORA-00928 在 Oracle 中缺少 SELECT 关键字 - ORA-00928 missing SELECT keyword in Oracle java.sql.SQLException:ORA-00928:缺少SELECT关键字。 使用JDBC将记录插入DB时 - java.sql.SQLException: ORA-00928: missing SELECT keyword. when inserting record to DB using JDBC java.sql.SQLSyntaxErrorException:ORA-00936:缺少表达式 - java.sql.SQLSyntaxErrorException: ORA-00936: missing expression java.sql.SQLSyntaxErrorException:ORA-00922:缺少或无效的选项 - java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option 使用别名时,JDBC结果集不起作用,我收到“ java.sql.SQLSyntaxErrorException:ORA-00905:缺少关键字” - JDBC resultset not working when using aliases I receive “ java.sql.SQLSyntaxErrorException: ORA-00905: missing keyword” java.sql.SQLSyntaxErrorException: ORA-01722 - java.sql.SQLSyntaxErrorException: ORA-01722 java.sql.SQLSyntaxErrorException:ORA-01747 - java.sql.SQLSyntaxErrorException: ORA-01747 java.sql.SQLSyntaxErrorException:ORA-00907:缺少右括号错误 - java.sql.SQLSyntaxErrorException: ORA-00907: missing right parenthesis Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM