Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

problem in entering values

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii..thnks for ur advice
this time i have used java.io for
enterin values
but again the program is compiling but
values r not entered..plzz help


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


public class buffer

{

public static void main(String [] args)

{
//try{
String ss;
while(true)
{
ss = getLine();
ss = ss.trim();
if (ss.charAt(0) == 'q') System.exit(0);
System.out.println("mef"+ss);


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;


m= st.executeUpdate("insert into mayank values(ss) ");

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());
*/
}







}
} // end main
/**
* reads a line from STDIN
*/
public static String getLine () {
StringBuffer buf = new StringBuffer(80);
int c;
try {
while ((c = System.in.read()) != -1) {
char ch = (char) c;
if (ch == '\n') break;
buf.append(ch);
}
}
catch (IOException e) {
System.err.println(e);
}
return (buf.toString());
}
}
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


insert into mayank values(ss)


That is not valid SQL. Assuming you are trying to enter a record into a table called "mayank" that has only one column which is a character datatype it should probably be this:


Thinks to note: its not good practice to comment the code which logs an exception message. Without the exceptions message all you can do is guess.

Its a good idea to post the exception message you see when you create a topic; it helps those who might respond.

Please don't post topics using abbreviated language (ur, r, plzz etc.) - it makes you posts difficult to read.
 
Sheriff
Posts: 67389
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

Please read this for more information.

thanks,
bear
Forum Bartender
 
Danger, 10,000 volts, very electic .... 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
    Bookmark Topic Watch Topic
  • New Topic