Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

method always visible by other class

Thread view: 
Mariano - 18 Mar 2007 20:55 GMT
Then I have a class called MyDBConn.java, inside this class there's a
method called GetResultFromPazienti():

MyDBConn.java:
==================================

package cc;

import java.sql.*;

public class MyDBConn {
   private Connection myConnection;
   private java.sql.Statement stmt;

// ...

public ResultSet getResultFromPazienti2(String query) {
       ResultSet rs=null;
       try{
           rs=stmt.executeQuery(query);
       }
       catch(Exception e){
           alerts.showErr(e.getMessage());
       }
       return rs;
   }

// ...

==================================

After this, I have a class called Paziente.java, from this class I
would call method: getResultFromPazienti2(), class is something like
this:

File: Paziente.java
==================================
package cc;
import java.sql.*;

public class Paziente extends javax.swing.JFrame {
       private MyDBConn mdbc;
       private java.sql.Statement stmt;

// ...
// ...

   private void formWindowOpened(java.awt.event.WindowEvent evt)
{
       ResultSet rs=mdbc.getResultFromPazienti2("select ... from ...
where ...");

       try {
           rs.next();
                // ...
                txtNome.setText(rs.getString("NOME"));
                // ...
       } catch (SQLException ex) {
           ex.printStackTrace();
       }
   }
}

==================================

At first moment seem that are not problems, infact there's no problem
in compile time, but when I execute project and method
formWindowOpened() is started an "Exception in thread "AWT-
EventQueue-0" java.lang.NullPointerException", where are the
problems???
Thank you to all....
Brandon McCombs - 19 Mar 2007 02:15 GMT
> Then I have a class called MyDBConn.java, inside this class there's a
> method called GetResultFromPazienti():

The method below is called GetResultFromPazienti2().

> MyDBConn.java:
> ==================================
[quoted text clipped - 8 lines]
>
> // ...

the method below is not the same as you specify above.
You never instantiate stmt so maybe that is what is producing the null
pointer.

> public ResultSet getResultFromPazienti2(String query) {
>         ResultSet rs=null;
[quoted text clipped - 23 lines]
>         private MyDBConn mdbc;
>         private java.sql.Statement stmt;

Is stmt ever used and initialized?
Is mdbc ever initialized? You leave out code that prevents full analysis
so we can't help you.

> // ...
> // ...
[quoted text clipped - 23 lines]
> problems???
> Thank you to all....

The exception should tell you what line the null pointer is on. Does it?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.