Solved

Coonection Problem in java (oracle)

Posted on 2009-07-08
3
150 Views
Last Modified: 2013-11-23
Hi ,

i am using 2 java class ,

1st class  program

DBConn dba=new DBConn();
Connection con=null;

String query="insert into gen_info(EMP_NAME,EMP_ID,TECH) "+ "values(?,?,?)";
//Statement st=con.createStatement();
PreparedStatement psmnt=null;
dba.DBAccess(query);
psmnt.setString(1,"Sathish");
psmnt.setString(2,"E11006");
psmnt.setString(3,"Java");

boolean s = psmnt.execute();
if (s)
{
      System.out.println("Succesfully inserted");
}
else
{
      System.out.println("Cant Insert");
}
      //st.execute(query);
con.close();


its call DBConn class , thats have connection coding
 Class.forName("oracle.jdbc.driver.OracleDriver");
                              // System.out.println("Failed to load isqlPlus driver.");
                              //DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                        }

                        catch (Exception ae) {
                              ae.printStackTrace();
                        }

                        try {

                              String url1 = System.getProperty("JDBC_URL");
                              if (url1 != null)
                                    url = url1;
                              PreparedStatement psmnt=null;
                              con = DriverManager.getConnection(url,
                                          "system", "tspl");
                              psmnt = con.prepareStatement(query);
                              
                        } catch (Exception e) {
                              e.printStackTrace();
                        }
                        
                  } catch (Exception e) {
                        e.printStackTrace();
                  }

afterfinish this its return back to 1st  preparestmaent is null its throw the null pointer excetion
kindly help me to reslove this !!

             
                  
0
Comment
  • 2
3 Comments
 
LVL 2

Expert Comment

by:sirtam
ID: 24807142
Hi.

Did you remember to make objects of the connections? ( = new ...())

http://www.experts-exchange.com/Programming/Languages/Java/Q_24534178.html
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 24810959
I am using 2 class sirtam so preparestatement variable is null when the nrturn back excute the query .
0
 
LVL 20

Accepted Solution

by:
Sathish David  Kumar N earned 0 total points
ID: 24924004
prepareStament is local to that class so thats value is null so its say null ponter exception
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 71
array11 challenge 16 51
pairs challenge 5 44
Java array passed to SQL where clause 23 40
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now