Results 1 to 2 of 2

Thread: Null Values...

  1. #1
    Join Date
    Oct 2012

    Unanswered: Null Values...

    I'm getting "null" values in the line that reads
    "arrivalThreadRegnum = Integer.parseInt(rs1.getString(1).trim())"

    When I'm in debug mode and I highlight "rs1" it states that the "columnLabelToIndex= null" and "columnNameToIndex= null".

    My question is, how do I change these values from being null

    Any help would be greatly appreciated!!

    Code below...

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.Vector;

    public class SlotReservation {

    Vector<Integer> summaryVector = newVector<Integer>();
    ArrayList<slotInfo> defragList = new ArrayList<slotInfo>();
    int[][] bitMap=new int [48][500];

    public static void main(String[] args){
    int[] values = {10,20,5,3,100,105};
    int min = Integer.MAX_VALUE;
    for ( int d = 0; d < values.length; d++ ){
    if ( values[d] < min ){
    min = values[d];
    system.out.println("MIN HAS BEEN SET");


    SlotReservation userPL = new SlotReservation();
    userPL.summaryVector = new Vector<Integer>();
    userPL.defragList = new ArrayList<slotInfo>();
    int answerLimit = 0;

    //Arrival Thread Variable initialization

    int slotNumber = 0;
    int startTime = 1001;
    int endTime = 1053;
    int arrivalThreadRegnum = 1000;

    //Setting up database connection

    Connection conn = null;


    String userName = "root";
    String password = "";
    String url = "jdbc:mysql://localhost/mysql";
    Class.forName ("com.mysql.jdbc.Driver").newInstance ();
    conn = DriverManager.getConnection (url, userName, password);
    catch (Exception e)
    System.err.println ("Cannot connect to database server");
    if (conn != null)
    Statement stmt = null;
    int answer=1;
    stmt = conn.createStatement();
    ResultSet rs=stmt.executeQuery("SELECT MIN(car_regnum), start_time,end_time FROM fsbm_data where temp_present='0' and temp_block='0'");

    if (
    System.out.println("Selecting the correct constructor");
    new DefragmentAllocations3(userPL);
    //new DefragmentAllocations2(userPL);
    //new DefragmentAllocations(userPL);


    for (int i = 0; i < answer; i++)

    //Selecting a user randomly from the user table such that he is not in the parking lot and has not been used till now.

    ResultSet rs1=stmt.executeQuery("SELECT MIN(car_regnum), start_time,end_time FROM fsbm_data where temp_present='0' and temp_block='0'");

    if (
    arrivalThreadRegnum = Integer.parseInt(rs1.getString(1).trim());
    startTime = Integer.parseInt(rs1.getString(2).trim());
    endTime = Integer.parseInt(rs1.getString(3).trim());
    stmt.executeUpdate("UPDATE fsbm_data set temp_present=1, temp_block=1 where car_regnum="+rs1.getString(1));

    //Calling thread for each new user and sending his registration number and advance reservation spot number

    new FreeSpaceDetection(userPL.summaryVector,userPL.bit Map,arrivalThreadRegnum, startTime,endTime,userPL.defragList);


    if (rs.wasNull())

    System.out.print ("NULL");

    catch (InterruptedException e)


    System.out.println("No more users available to simulate the arrival threads");

    System.out.println("The min value is " + min);

    catch (SQLException e1)
    } finally {

    System.out.println("DEFRAG LIST AT END OF MAIN IS "+ userPL.defragList);

  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    NULL values are a perfectly reasonable value in a database driven application.
    You need to understand what a NULL value represents
    ..NULL values represent where there is no value
    support a representation of "missing information and inapplicable information"
    . there's probably different or better descriptions elsewhere.. but that'll do. Its important to flag the difference between a NULL value and a default value. Some proponents advocate that NULL values shouldn't exists in a Relational DB.

    You need to understand how a NULL value can be in the system
    It can occur because there is no data in that column for that row (IE there is no data there). if that is a problem then you should look at the column definition and consider if you should block NULL for that column
    Some DB interfaces return NULL values on finding no records. check how your proposed DB interface handles rows not found.

    Most languages have special mechanism of dealing with NULL values, not using those mechanism's usually flags the error you are reporting. SO its donw to how your code deals with NULLs.
    either dont' allow 'em in the first place
    design your code to spot NULL values and deal with them appropriately
    so in this instance
    I'd suggest you need to check if the value returjned from the db for rs1 is NULL
    if it isn't then
    arrivalThreadRegnum = Integer.parseInt(rs1.getString(1).trim())
    if it is NULL then supply an appropriate value
    if there shoudl have been a value and there isn't then ytou need to take appropriate action elsewhere. IE where ever the data is captured that process shgould ensure an appropriate value is stored. you can enforce that by defining the column as NOT NULL so that NULL values are not accepted.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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