double execution to insert into database ?!? help me someone

Sorry if i have repost something similar to my previous post... but somehow i think i really need a major help in this. I need to write 2 lines of executeUpdate() then i am able to insert a new record into my database...i figure for so long and still couldnt solve this bug in my application. Hope someone can offer me a solution to me... thanks in advance.

Peixing.

import java.io.*;

public class Index{

public static void main(String[] args)throws IOException{

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

String userId = "";

String userPw = "";

String email = "";

System.out.println("Welcome to New World Inc.");

System.out.println("1. Create new user");

System.out.println("1. Login application");

System.out.println("3. Exit application");

int choice = 0;

do{

System.out.print("Please select an option: ");

try{

choice = Integer.parseInt(input.readLine());

}

catch(NumberFormatException e){

//e.printStackTrace();

choice = 0;

}

}while(choice<1 || choice>3);

if(choice==1){

Account acc = new Account();

do{

System.out.print("Enter user name: ");

try{

userId = input.readLine();

int idSize = userId.length();

}

catch(Exception e){

e.printStackTrace();

}

}while(userId.equals(""));

}

}

}

import java.sql.*;

public class Account{

DBC dbc;

public Account(){

dbc = new DBC();

dbc.setUp("database");

}

public void setUserId(String userId){

int status = dbc.updateRequest("INSERT INTO Account VALUES('" + userId + "','','')");

dbc.updateRequest("INSERT INTO Account VALUES('" + userId + "','','')");<=====i wonder why i need to write an additional updateRequest then i am able to insert a new record into my database.... its so weird. and everytime i take away this additional method, i cannot add a new record into my database}

}

import java.sql.*;

public class DBC{

private Connection con;

public void setUp(String dsn){

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(Exception e){

System.out.println("Load driver error");

}

try{

String s = "jdbc:odbc:" + dsn;

con = DriverManager.getConnection(s, "", "");

}

catch(Exception e){

e.printStackTrace();

}

}

public ResultSet readRequest(String dbQuery){

ResultSet rs=null;

try{

Statement stmt = con.createStatement();

rs = stmt.executeQuery(dbQuery);

}

catch(Exception e){

e.printStackTrace();

}

return rs;

}

public int updateRequest(String dbQuery){

int count=0;

try{

Statement stmt = con.createStatement();

stmt.executeUpdate(dbQuery);

count = 1;

}

catch(Exception e){

count = -1;

}

return count;

}

}

[3071 byte] By [peixinga] at [2007-11-27 11:20:38]
# 1

sorry, i need to edit to this post

acc.setUserId(userId); <=== i forgot to add this line after int idSize = userId.length();

so sorry for those trying to help me through this mess.....

peixinga at 2007-7-29 14:43:50 > top of Java-index,Java Essentials,Java Programming...
# 2

Please repost your code using the code tags.

cotton.ma at 2007-7-29 14:43:50 > top of Java-index,Java Essentials,Java Programming...
# 3

import java.io.*;

public class Index{

public static void main(String[] args)throws IOException{

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

String userId = "";

String userPw = "";

String email = "";

System.out.println("Welcome to New World Inc.");

System.out.println("1. Create new user");

System.out.println("1. Login application");

System.out.println("3. Exit application");

int choice = 0;

do{

System.out.print("Please select an option: ");

try{

choice = Integer.parseInt(input.readLine());

}

catch(NumberFormatException e){

//e.printStackTrace();

choice = 0;

}

}while(choice<1 || choice>3);

if(choice==1){

Account acc = new Account();

do{

System.out.print("Enter user name: ");

try{

userId = input.readLine();

int idSize = userId.length();

acc.setUserId(userId);

}

catch(Exception e){

e.printStackTrace();

}

}while(userId.equals(""));

}

}

}

import java.sql.*;

public class Account{

DBC dbc;

public Account(){

dbc = new DBC();

dbc.setUp("database");

}

public void setUserId(String userId){

int status = dbc.updateRequest("INSERT INTO Account VALUES('" + userId + "','','')");

dbc.updateRequest("INSERT INTO Account VALUES('" + userId + "','','')");//<===== i wonder why i need to write an additional updateRequest then i am able to insert a new record into my database.... its so weird. and everytime i take away this additional method, i cannot add a new record into my database

}

}

import java.sql.*;

public class DBC{

private Connection con;

public void setUp(String dsn){

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

}

catch(Exception e){

System.out.println("Load driver error");

}

try{

String s = "jdbc:odbc:" + dsn;

con = DriverManager.getConnection(s, "", "");

}

catch(Exception e){

e.printStackTrace();

}

}

public ResultSet readRequest(String dbQuery){

ResultSet rs=null;

try{

Statement stmt = con.createStatement();

rs = stmt.executeQuery(dbQuery);

}

catch(Exception e){

e.printStackTrace();

}

return rs;

}

public int updateRequest(String dbQuery){

int count=0;

try{

Statement stmt = con.createStatement();

stmt.executeUpdate(dbQuery);

count = 1;

}

catch(Exception e){

count = -1;

}

return count;

}

}

peixinga at 2007-7-29 14:43:50 > top of Java-index,Java Essentials,Java Programming...