This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters

 
mansi gandhi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.sql.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;


public class DBConnectie{

String DBName, DBUser, DBPass, SQLQuery;
Connection conn;
Statement stmt;
ResultSet result;
String parent1;
String storyname;
String parent2;
String parent3;
String target;
String event;
String str;
String path;

public DBConnectie(String DBName,String DBuser , String DBPass)
{
this.DBName = DBName;
this.DBUser = DBUser;
this.DBPass = DBPass;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}

catch(Exception e)
{
System.err.println(e);

}
}



public void connect()
{
try {
conn=DriverManager.getConnection("jdbcdbc:eventdata");
//conn = DriverManager.getConnection("jdbc:mysql://localhost/" + DBName + "?user=" + DBUser + "&password=" + DBPass);
}catch(Exception e){System.out.println(e + "HELLOOOO");}
}

public ResultSet selectQuery(String SQLQuery)
{
this.SQLQuery = SQLQuery;

try {
stmt = conn.createStatement();
result = stmt.executeQuery( "SELECT"+" name"+"password"+ "FROM online" );
}
catch( Exception e ){System.err.println(e+"catch 2345");}
return result;
}

public void query(String SQLQuery)
{
this.SQLQuery = SQLQuery;
try {
stmt = conn.createStatement();
stmt.executeQuery( "SELECT storyname,parent1,parent2,parent3,target,event,story FROM data");
}catch( Exception e ){System.err.println(e+"mansi");}
}

public void close()
{
try {
stmt.close();
conn.close();
}
catch(Exception e){System.err.println(e+"hi");}
}
}

this is my code and im getting the above show error plzz help i hav checked the data base
my database is in MS ACCESS.all tables are proper i need urgent help
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mansi,

Welcome to Javaranch.

Originally posted by mansi gandhi:
i need urgent help


I would like to refer some reading about..How To Ask Questions On JavaRanch and regarding your urgent help -> Ease Up
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
result = stmt.executeQuery( "SELECT"+" name"+"password"+ "FROM online" );

I doubt that this line does anything useful. Have you checked the query that you're sending to the DB (maybe by printing it to the console)?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't indicated which line throws the Exception, but I'm guessing this one:


Take out the obfuscation and you get the following:



The database thinks you are refering to a parameter, which has not been specified. I believe you mean to say:

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
d'oh
 
mansi gandhi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try {
stmt = conn.createStatement();
stmt.executeQuery( "SELECT storyname,parent1,parent2,parent3,target,event,story FROM data");
}catch( Exception e ){System.err.println(e+"mansi");}
}
this part of my code is giving exception
 
mansi gandhi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried what you told me to but still I'm getting the same error..
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mansi gandhi:
SELECT storyname,parent1,parent2,parent3,target,event,story FROM data


Check each of these table attributes and make sure the spelling is the same as the in the database
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or check your attribute in your data table, does all of these attribute are exist.
 
Jhakda Velu
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I don't think "Too few Parameters" exception would be thrown for a simple select statement like yours. Can you post the full error stack trace? This will enable folks to narrow down to the problem faster.
Are you sure that you are able to connect to the DB?
Jhakda
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic