Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Exclamation sql statement problem

    Hi,
    I have been assigned a task at work but i'm a beginner in Java and Eclipse.
    I have to re-use an existing programm and modify some parts of it.
    The following part does'nt work:

    "
    private java.sql.Connection conn;
    private final String sqlRequest = "select ... from ...";
    ................
    try {
    // create SQL statement

    java.sql.Statement stmt = conn.createStatement();
    java.sql.ResultSet rs = execRequest(stmt,sqlRequest); ...............................
    "

    The error message in eclipse is : "java.lang.NullPointerException at mon_prog.search2(mon_prog.java:135)"

    This part used to work before... so is the problem due to my JDK version? I have JDK7u2

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,845
    Rep Power
    19

    Default Re: sql statement problem

    What is null at line 135?

  3. #3
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: sql statement problem

    line 135 is java.sql.Statement stmt = conn.createStatement();

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,845
    Rep Power
    19

    Default Re: sql statement problem

    So 'conn' is null.
    Where is 'conn' being set?

  5. #5
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: sql statement problem

    I have this:

    private void DBConnect(){
    try {
    // Load the driver
    java.lang.Class.forName(jdbcdriver).newInstance();
    // Connect to database
    conn = java.sql.DriverManager.getConnection(jdbcURL,dbuse r,dbpwd);

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,845
    Rep Power
    19

    Default Re: sql statement problem

    Well, then that isn't being run, or it is throwing an exception and so failing to create 'conn', or that 'conn' isn't the 'conn' that is null on line 135.

    That is all that can be said with the information given.

Similar Threads

  1. INSERT SQL statement problem
    By Johanis in forum New To Java
    Replies: 13
    Last Post: 11-09-2011, 03:33 PM
  2. Problem with if statement
    By SiX in forum New To Java
    Replies: 8
    Last Post: 07-22-2011, 07:49 PM
  3. Problem with if statement - Char
    By KardKaper in forum New To Java
    Replies: 8
    Last Post: 12-22-2009, 01:14 PM
  4. If-Else statement problem
    By MomenT in forum New To Java
    Replies: 9
    Last Post: 10-23-2008, 08:06 AM
  5. Please help me with this Problem Statement
    By KMS in forum New To Java
    Replies: 1
    Last Post: 09-22-2008, 08:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •