• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Problem

 
iamontheinet
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
this is driving me crazy; i'm trying to retrieve records from a local oracle database (on my laptop) - the oracle driver gets registered, it connects to the database BUT when i try to executeQuery() with a valid SQL it throws the following exception;
Exception occurred during event dispatching:
java.lang.NullPointerException at Retrieve.retrieve(Retrieve.java:103)...........
i have also tried using an Access db but it throws the same exception. what am i missing ???
NOTE : using jdk 1.3 and oracle 7.3.4
any help will be appreciated.
thanx
go java !!
 
Atonu Bhowmik
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friend!
The problem may be with undefined resultset.After the connection follow the given below lines:
Statement st = cn.createStatement()
ResultSet rs1 = st.executeQuery("select * from *table name*");
while(rs.next())
{System.out.println(rs.getInt("field name"));
}
I hope this will solve the problem.
regards,
Atonu Bhowmik
[This message has been edited by Paul Wheaton (edited November 13, 2000).]
 
Monty Ireland
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code works for me.
JDK 1.3 / JDBC ver 1.0 / NT / Oracle 7.3.4 on a unix box.
Hope this helps...
<code>
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {

String url = "jdbc racle:thin:@hostname:1521:sid";
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME varchar(32), " +
"SUP_ID int, " +
"PRICE float, " +
"SALES int, " +
"TOTAL int)";
Statement stmt;

try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}

catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url "USERID", "PASSWORD");
stmt = con.createStatement(); stmt.executeUpdate(createString);
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
} // end of main
} // end of class
</code>

[This message has been edited by Monty Ireland (edited November 08, 2000).]
[This message has been edited by Monty Ireland (edited November 08, 2000).]
[This message has been edited by Monty Ireland (edited November 09, 2000).]
 
paul wheaton
Trailboss
Pie
Posts: 21887
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgive my edits above, but the angle brackets in the message were being interpretted as html and made the whole page unviewable.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Ranch has a naming policy, described here and "iamontheinet" is not a valid name. Please choose one which meets the requirements.
Thanks.
 
dhams des
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys, thanx for your responses.
frank, i have changed my username.
 
Frank Carver
Sheriff
Posts: 6920
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic