问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

java连接oracle数据库java.sql.SQLException:无效的列索引问题?

发布网友 发布时间:2022-04-07 16:49

我来回答

2个回答

热心网友 时间:2022-04-07 18:18

java.sql.SQLException: 无效的列索引

无效的列索引

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207)

atoracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:5328)

atoracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:5320)

at untitled5.addreader1.validID(addreader1.java:128)

at untitled5.addreader1.jButton1_actionPerformed(addreader1.java:97)

at untitled5.addreader1_jButton1_actionAdapter.actionPerformed(addreader1.java:175)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

代码:String driverName = "oracle.jdbc.OracleDriver";

Driver driver = (Driver) Class.forName(driverName).newInstance();

//连接数据库

Connection con = DriverManager.getConnection(

"jdbc:oracle:thin:@LONG:1521:orcl", "sysman", "tongfang");

PreparedStatement pstmt = con.prepareStatement(

" insert into reader values(?)");

pstmt.setString(1, str1);

pstmt.setString(2,str2);

pstmt.setString(3,str3);

pstmt.setString(4,str4);

ResultSet res = pstmt.executeQuery();

java.sql.SQLException: 无效的列索引

无效的列索引

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:207)

atoracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:5328)

atoracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:5320)

at untitled5.addreader1.validID(addreader1.java:128)

at untitled5.addreader1.jButton1_actionPerformed(addreader1.java:97)

at untitled5.addreader1_jButton1_actionAdapter.actionPerformed(addreader1.java:175)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)

at java.awt.Component.processMouseEvent(Unknown Source)

at javax.swing.JComponent.processMouseEvent(Unknown Source)

at java.awt.Component.processEvent(Unknown Source)

at java.awt.Container.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source

at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

at java.awt.Container.dispatchEventImpl(Unknown Source)

at java.awt.Window.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

代码:String driverName = "oracle.jdbc.OracleDriver";

Driver driver = (Driver) Class.forName(driverName).newInstance();

//连接数据库

Connection con = DriverManager.getConnection(

"jdbc:oracle:thin:@LONG:1521:orcl", "sysman", "tongfang");

PreparedStatement pstmt = con.prepareStatement(

" insert into reader values(?)");

pstmt.setString(1, str1);

pstmt.setString(2,str2);

pstmt.setString(3,str3);

pstmt.setString(4,str4);

ResultSet res = pstmt.executeQuery();

热心网友 时间:2022-04-07 19:36

pstmt.setString(1,
str1);
pstmt.setString(2,str2);
pstmt.setString(3,str3);
pstmt.setString(4,str4);
这是对SQL语句中,第1至第4个占位符进行值的填充,是针对一条SQL语句的。而你的SQL语句中只有1个占位符,所以第2至第4个的填充,程序就无法处理了。
你是想要插入4条记录吗?那在填充值和pstmt.executeQuery()这两句代码使用循环呗
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
说课包括哪些方面 说课内容包括()。 如何在手机百度上删除对话记录? 结核病是什么样的疾病? 曹丕17岁得了肺痨,明知自己命不长久,还要强争王位,是不是很自私呢?_百... 古代小说常出现的病名 急求一篇"生活小窍门"(500字)的作文 至今最有什么小妙招 健康的戒烟方法 笔记本电池锁死是什么原因引起的? 小瓜怎么吃 三星s7记事本怎么用 小个子穿搭,保暖又显高、可盐可甜的搭配是什么? 三星s5记事本在哪 三星a7中记事本在什么位置 今年流行的“优雅紫”,可盐可甜,该怎么搭配呢? 三星手机a5记事本功能在哪里 可盐可甜的韩范穿搭,最关键的细节是什么? 我是三星D908i的水货手机。请问怎样才能在手机上打开WORD文档和记事本。 可盐可甜的春季穿搭,适合酷女孩儿,你怎么看呢? 三星s8记事本在哪里 夏天想要穿得清爽减龄,可甜可盐又洋气舒适,你心动了吗? 换条裙子就能改变气质?推荐你入手这几条,可盐可甜风格超百变,你怎么看? 减龄粉色连衣裙搭配一双小白鞋,可盐可甜的风格你喜欢吗? 三星手机记事本打不开怎么办 造型可甜可盐的舒畅,穿上红色连衣裙,魅力如何? 三星手机S21有备忘录或记事本吗? 三星note4找不到记事本 如何 添加m3u8的节目源 m3u8的直播为什么循环播放/播放几秒就停止了 金晨的穿搭可盐可甜,高个子女生怎样搭配才能化身“甜girl”? 跟着宋茜学穿搭,可盐可甜,她有哪些比较适合大学生去尝试的风格? 想穿出少女感,有哪些可盐可甜的时尚搭配? 阿尔卑斯糖果的含义是什么?每个口味又有什么含义 阿尔卑斯糖的定义是什么? 阿尔卑斯糖的来历是什么? 问一些家电维修用到的 IC功能 阿尔卑斯糖的含义 lc7881dac解码芯片怎么样 哈密瓜脯如何加工? lc89950各脚电压 送女孩阿尔卑斯奶糖有什么意义? 冬瓜糖的制作 阿尔卑斯棒棒糖一袋里有多少个? sg3524的引脚功能是什么? 运动鞋上的logo怎么去除? 阿尔卑斯糖送人的含义是什么? 三洋LC7267是什么功能的IC? 阿尔卑斯糖的意义是什么 如何辨别真假阿尔卑斯糖果?