Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

problem in entering values

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());
*/
}

}






}
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic