This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JDBC and the fly likes problem in entering values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in entering values" Watch "problem in entering values" New topic
Author

problem in entering values

mayank yadav
Greenhorn

Joined: Sep 25, 2005
Posts: 11
i have now tried this
program using buffer reader
where the input is saved in the string ss
and then passed to the sql statement...
but iam gettin an exception ..saying too few parameters..
please help me...iam struck with this for a long time...


import java.io.*;
import java.sql.*;



class buffer1
{
public static void main(String ar[])
throws IOException
{



BufferedReader stdin = new BufferedReader ( new InputStreamReader( System.in ) );

String line1;
// declaration of input Strings
int first;
// declaration of int variables

System.out.println("Enter first Name:");
line1 = stdin.readLine();
//first = Integer.parseInt( line1 ); // convert line1 to first int
System.out.println("The name is " +line1);



try {

// Step 1: Load the JDBC driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// Step 2: Establish the connection to the database.
String url = "jdbc dbc:mayank";
Connection conn = DriverManager.getConnection(url,"","");
Statement st = conn.createStatement();



//these two statements does not execute durin the program

int m;

//String k= "line1";
m= st.executeUpdate("insert into mayank(class) values(line1) ");

ResultSet rs;

rs= st.executeQuery("select class,name from mayank ");


conn.commit();

while(rs.next())

{
String n= rs.getString("name");
String c = rs.getString("class");
System.out.println(n + " " + c);
}


}

catch (Exception e)

{
e.printStackTrace();
/*System.err.println("Got an exception! ");
System.err.println(e.getMessage());
*/
}

}






}
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

When you insert a string into SQL you must put single quotes around it, otherwise it gets treated like a variable. This is warning you that it has detected a variable without a value 'bound' to it.



Dave
Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
Originally posted by David O'Meara:
When you insert a string into SQL you must put single quotes around it, otherwise it gets treated like a variable. This is warning you that it has detected a variable without a value 'bound' to it.



Dave


or else a preparedstatement can be used.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

If you do a quick search of the JDBC forum I always prefer PreparedStatements
In this case I just wanted to help solve the problem.

If we're offering other useful advice: avoid the JDBC-ODBC bridge and use another database and driver.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem in entering values
 
Similar Threads
uanble to wstavlish connection using JDBC and applet
linking JDBC with Applet
problem in enterin data through jdbc:odbc
problem in entering values
how to use prepared statement in the given code