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;
try
{
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");
}
finally
{
if (conn != null)
{
Statement stmt = null;
int answer=1;
try
{
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 (rs.next())
{
System.out.println("Selecting the correct constructor");
new DefragmentAllocations3(userPL);
//new DefragmentAllocations2(userPL);
//new DefragmentAllocations(userPL);
}
while(answer<1750)
}
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 (rs1.next())
{
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.bitMap,arrivalThreadRegnum, startTime,endTime,userPL.defragList);
slotNumber++;
if (rs.wasNull())
System.out.print ("NULL");
}
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
System.out.println("No more users available to simulate the arrival threads");
{
}
System.out.println("The min value is " + min);
System.out.println(Integer.MAX_VALUE);
}
catch (SQLException e1)
{
e1.printStackTrace();
} finally {
}
}
}
System.out.println("DEFRAG LIST AT END OF MAIN IS "+ userPL.defragList);
}
}
}
}