File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "problem in entering values" Watch "problem in entering values" New topic

problem in entering values

mayank yadav

Joined: Sep 25, 2005
Posts: 11
hii..thnks for ur advice
this time i have used for
enterin values
but again the program is compiling but
values r not entered..plzz help

import java.sql.*;

public class buffer


public static void main(String [] args)

String ss;
ss = getLine();
ss = ss.trim();
if (ss.charAt(0) == 'q') System.exit(0);

try {

// Step 1: Load the JDBC driver.

// 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 ");



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


catch (Exception e)

/*System.err.println("Got an exception! ");

} // end main
* reads a line from STDIN
public static String getLine () {
StringBuffer buf = new StringBuffer(80);
int c;
try {
while ((c = != -1) {
char ch = (char) c;
if (ch == '\n') break;
catch (IOException e) {
return (buf.toString());
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

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.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63869

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.

Forum Bartender

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: problem in entering values
It's not a secret anymore!