Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error: Invalid parameter index

843859Aug 7 2008 — edited Mar 25 2009
Hi, I'm using jtds 1.2 driver for sql server 05.
Error:
java.sql.SQLException: Invalid parameter index 1.
	at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.getParameter(JtdsPreparedStatement.java:255)
	at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setParameter(JtdsPreparedStatement.java:326)
	at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setObjectBase(JtdsPreparedStatement.java:312)
	at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setObject(JtdsPreparedStatement.java:584)
	at org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:165)
	at com.eglue.dbconnectivity.utils.MyTest.f(MyTest.java:44)
	at com.eglue.dbconnectivity.utils.MyTest.main(MyTest.java:60)
Code:
package com.eglue.dbconnectivity.utils;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import org.apache.commons.dbcp.BasicDataSource;
import com.eglue.exception.ExecutingQueryException;

public class MyTest {

	public void f() 
	{
		Connection connection = null;
		CallableStatement callableStatement = null;
	
			
			try {
				Class.forName ("net.sourceforge.jtds.jdbc.Driver");
			} catch (ClassNotFoundException e2) {
			
				e2.printStackTrace();
			}
			BasicDataSource bds = new BasicDataSource();
			
			bds.setUrl("jdbc:jtds:sqlserver://192.168.0.29:1433;database=dbName");
			bds.setPassword("***");
			bds.setUsername("***");
			
			try {
				connection = bds.getConnection();
			} catch (SQLException e) {
				
				e.printStackTrace();
			}
			try {
				callableStatement = connection.prepareCall("SELECT * FROM cm_attr WHERE category=? ");
			} catch (SQLException e1) {
			
				e1.printStackTrace();
			}
		
				try {
					callableStatement.setObject(1, "LDAP");
					
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				try {
					callableStatement.execute();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			
	}
			
		
	
	public static void main(String[] args) 
	{
		
		MyTest testJdbc = new MyTest();
		testJdbc.f();
	}

}
Thank's alot for your help!
Yael
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 22 2009
Added on Aug 7 2008
12 comments
8,036 views