java - JDBC Connection connected but no query result to the resultset -
i trying project has major problem. created table test2 attribute cid. added user cid using these command line in sql command line:
create table test2(cid varchar(20)); insert test2 values('hello'); select cid test2;
then result
cid ----------------------- hello
my question when tried use jdbc eclipe server, rs.next() false (rs resultset). have 'hello' inside table test2. here code, if me out this, appreciate it:
public boolean connect(string username, string password) { string connecturl = "jdbc:oracle:thin:@dbhost.xxx.xx.xxx.ca:1522:ug"; try { con = drivermanager.getconnection(connecturl,username,password); system.out.println("\nconnected oracle!"); resultset rs; try { statement stmt = con.createstatement(); rs = stmt.executequery("select cid test2"); system.out.println("here"); while(rs.next()) { system.out.println("there"); system.out.println("cid isssssssssss: " + rs.getstring("cid")); } system.out.println("after here"); stmt.close(); } catch (sqlexception ex) { system.out.print("message: " + ex.getmessage()); } try { con.close(); } catch (sqlexception e1) { // todo auto-generated catch block e1.printstacktrace(); } return true; } catch (sqlexception ex) { system.out.println("message: " + ex.getmessage()); return false; } }
connection there because when change cid else sqlexception gave me error message. connects not getting query server.
rs = stmt.executequery("select test2"); connected oracle! message: ora-00904: "something": invalid identifier
puzzling me. again.
you ask:
i have data in database. did not insert data eclipse instead used .sql file load database. need commit well?
i take using sql*plus load data database.
if so, commit
required unless sql*plus in "autocommit" mode.
sql*plus: sql> show autocommit; autocommit off sql> set autocommit on;
(without either "autocommit" or explicit commit
statement, transaction rolled when end sql*plus session. , explanation observing.)
Comments
Post a Comment