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

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)
at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:5328)
at oracle.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对应问题,大小写问题等等都没能解决,取消索引,单个插入就出现表或试图不存在,可用sqlplus又找得到数据表,都是用sysman的账户,这是什么原因呢,弄个一个下午了,请各位大牛帮忙,期末大作业,急急急!
好的。试试看。

这和用什么用户无关,只要能连上数据库、并且使用的用户对该表有插入权限,就没问题。现在出现的“无效的列索引的异常”,是指在语句pstmt.setString(2,str2);中,列索引2是无效的,因为sql语句中只有一个问号。PreparedStatement 对象中的
setString方法的第一个参数是列索引,这个参数的取值范围是和sql语句中的问号数量对应的,sql语句中有n个问号,setString方法的第一个参数就应该从1到n,如果不在这个范围之内,就会出列索引无效的异常。
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-05-09
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()这两句代码使用循环呗
第2个回答  2018-04-05

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();

本回答被网友采纳
第3个回答  2012-05-08
oracle.jdbc.driver.OracleDriver换个数据源看看
第4个回答  2012-05-08
索引要从0开始赋值

java连接oracle数据库java.sql.SQLException: 无效的列索引问题
这和用什么用户无关,只要能连上数据库、并且使用的用户对该表有插入权限,就没问题。现在出现的“无效的列索引的异常”,是指在语句pstmt.setString(2,str2);中,列索引2是无效的,因为sql语句中只有一个问号。PreparedStatement 对象中的 setString方法的第一个参数是列索引,这个参数的取值范围是和...

java连接oracle数据库java.sql.SQLException: 无效的列索引问题
at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:5320)看样子,是你用了一个压根没有的列序号。at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:5320)看样子,是你用了一个压根没有的列序号。

java连接oracle数据库java.sql.SQLException:无效的列索引问题?
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)...

java.sql.SQLException: 无效的列索引? 救命啊。help
java.sql.SQLException: 无效的列索引 “无效的列索引”其实是个低级的错误,原因无非几个:1、sql串的?号数目和提供的变量数目不一致:例如:jdbcTemplate.update(sql, new Object[] {newState,oldState});如果sql里面有1个?号,Object[]送了2个,就会报错。2、sql串里的?号书写不正确 英文?和...

在java连接oracle时候java.sql.SQLException: 无效的列索引_百度...
String str = "select * from management where name=? and password=?";String str = "select * from management where name='"+txtId.getText()+"' and password='"+txtPass.getText()+"'";pstat = datacon.prepareStatement(str);pstat.setString(1, txtId.getText());pstat.setString...

java jdbc查询数据库 无效的列索引
like后面写错了 应该是双百分号'%201301%'

java.sql.SQLException: 无效的列索引
String sql = "insert into student1 (name,age) values (name=?,age=?)";--此处就指定了两个?try { PreparedStatement ps = conn.prepareStatement(sql);ps.setString(2, name);--这个地方和 ps.setInt(3, age);--这个地方就错了哦 ps.execute();应该改成:ps.setString(1,name);-...

java.sql.SQLException: 无效的列索引
String sql2="insert into caselocus(id,pmid,caseno,flowtache,status,begindate,enddate) values(?,?,?,?,?,?,?)";改成 String sql2="insert into caselocus(pmid,caseno,flowtache,status,begindate,enddate) values(?,?,?,?,?,?)";\/\/pstmt.setInt(1, i); 这句去掉 这里id如果是...

java.sql.SQLException: 无效的列索引
sql语句的问题吧 这句 select dwmc,sum(unit) unitSum,sum(spds) spdsSum 应该是有问题的应该是 select dwmc,sum(unit),unitSum,sum(spds),spdsSum吧。

nested exception is java.sql.SQLException: 无效的列索引_百度...
你的Sql语句中。insert()这里面定义的操作列个数是9个。而values()里面实际传参数量是8个。传参数量不匹配。就造成了"无效列索引"的提示。你可以检查一下。values参数中,process_begin_time列值前应该还缺少一个参数

相似回答