aspose file tools*
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
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
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());
}
}
Paul Sturrock
Bartender

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
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in entering values