IndexOutOfBoundsException when trying to print data called from MySQL database - java

I'm getting a "java.lang.IndexOutOfBoundsException: Index: 0, Size: 0" and I don't even know what is wrong.
I have 4 classes. I get data from two MySQL databases in the first (ConnectionClass) and the second one is a main class from which I run and print the result but for some reason it doesn't work. The third and fourth are normal classes.
The first database is called account which has a few columns and a foreign key(f_id) from the second database f.
My Connection class:
package tryout;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class ConnectionClass {
Connection connection;
public void connect() {
String url = "jdbc:mysql://localhost:3306/mydemo";
String username = "root";
String password = "12345";
try {
connection = DriverManager.getConnection(url, username, password);
} catch (SQLException e) {
e.printStackTrace();
}
}
public ArrayList<F> getAllFs() {
connect();
ArrayList<F> l = new ArrayList<F>();
String sql="SELECT * FROM f";
try {
Statement s = connection.createStatement();
ResultSet rSet = s.executeQuery(sql);
while(rSet.next()) {
int j=0;
l.get(j).setF_id(rSet.getInt("f_id"));
l.get(j).setF_name(rSet.getString("f_name"));
j++;
}
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
return l;
}
public ArrayList<Account> getAllAccounts() {
connect();
ArrayList<Account> liste = new ArrayList<Account>();
String sql="SELECT * FROM account";
try {
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
while(rs.next()) {
int i=0;
liste.get(i).setUsername(rs.getString("username"));
liste.get(i).setPassword(rs.getString("password"));
liste.get(i).setFullname(rs.getString("fullname"));
liste.get(i).setEmail(rs.getString("email"));
liste.get(i).setWebsite(rs.getString("website"));
liste.get(i).setAge(rs.getInt("age"));
liste.get(i).setF((F) rs.getObject("f_id"));
i++;
}
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return liste;
}
}
My main class:
package tryout;
import java.util.ArrayList;
public class MAIN {
public static void main(String[] args) {
ConnectionClass class1 = new ConnectionClass();
ArrayList<Account> list = new ArrayList<Account>();
list = class1.getAllAccounts();
for(int i=0; i<list.size(); i++) {
System.out.println(list.get(i).getUsername()+" "+list.get(i).getPassword());
}
}
}
Account.java:
package tryout;
public class Account {
private String username;
private String password;
private String fullname;
private String email;
private String website;
private int age;
private F f;
public Account() {
super();
}
public Account(String username, String password, String fullname, String email, String website, int age, F f) {
super();
this.username = username;
this.password = password;
this.fullname = fullname;
this.email = email;
this.website = website;
this.age = age;
this.f = f;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public F getF() {
return f;
}
public void setF(F f) {
this.f = f;
}
}
F.java:
package tryout;
public class F {
private int f_id;
private String f_name;
public F() {
super();
}
public F(int f_id, String f_name) {
super();
this.f_id = f_id;
this.f_name = f_name;
}
public int getF_id() {
return f_id;
}
public void setF_id(int f_id) {
this.f_id = f_id;
}
public String getF_name() {
return f_name;
}
public void setF_name(String f_name) {
this.f_name = f_name;
}
}
Here are my databases:
I tried changing getAllAccounts to this:
public ArrayList<Account> getAllAccounts() {
connect();
ArrayList<Account> liste = new ArrayList<Account>();
ArrayList<F> l2 = new ArrayList<F>();
//l2 = getAllFs();
String sql="SELECT * FROM account";
try {
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
while(rs.next()) {
Account acc = new Account();
acc.setAge(rs.getInt("age"));
acc.setEmail(rs.getString("email"));
acc.setUsername(rs.getString("username"));
acc.setPassword(rs.getString("password"));
acc.setFullname(rs.getString("fullname"));
}
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
return liste;
}
and when i run it in the main class nothing shows. The error is gone but nothing is printed in the console.

The problem is with the following lines:
ArrayList<F> l = new ArrayList<F>();
String sql="SELECT * FROM f";
try {
Statement s = connection.createStatement();
ResultSet rSet = s.executeQuery(sql);
while(rSet.next()) {
int j=0;
l.get(j).setF_id(rSet.getInt("f_id"));
l.get(j).setF_name(rSet.getString("f_name"));
j++;
}
The list has no element but you are using l.get(j).
In order to understand this problem better, run the following code and you will get Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0.
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<String> l = new ArrayList<String>();
System.out.println(l.get(0));
}
}
Keeping aside the problem, you are initializing j inside while loop which means the incremented value is lost with every iteration. In order to solve the problem, replace
while(rSet.next()) {
int j=0;
l.get(j).setF_id(rSet.getInt("f_id"));
l.get(j).setF_name(rSet.getString("f_name"));
j++;
}
with
while(rSet.next()) {
l.add(rSet.getInt("f_id"));
l.add(rSet.getString("f_name"));
}

Related

How to pass the column name as dynamically in Postgres query in java

I want to pass the postgresql column names as dynamically on the execute query in java.I have created table and table name is product which has 4 columns(year, product,no,age).I have established the db connection and trying to pass the columns dynamically. I have created one pogo class which is having getter and setter of columns names.How can I pass the columns name dynamically on execute query.
dbcon.java
import java.sql.*;
import java.sql.Connection;
public class dbcon {
public static void main(String[] args) {
Connection conn =null;
Statement stmt = null;
DatabaseStatus databaseStatus = new DatabaseStatus();
try
{
Class.forName("******");
conn = DriverManager.getConnection("************", "*******", "*******");
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("Select "+databaseStatus.getYear()+","+databaseStatus.getProduct()+","+databaseStatus.getNo()+","+databaseStatus.getAge()+" FROM \"Products\";");
while(rs.next()){
System.out.println(rs.getString("Year").trim());
System.out.println(rs.getString("Product").trim());
System.out.println(rs.getString("No.").trim());
System.out.println(rs.getString("Age").trim());
}
}
catch (Exception e) {
e.printStackTrace();
}finally {
try {
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
datastatus.java
public class DatabaseStatus {
private String No;
private String Year;
private String Product;
private String Age;
public String getNo() {
return No;
}
public void setNo(String no) {
No = no;
}
public String getYear() {
return Year;
}
public void setYear(String year) {
Year = year;
}
public String getProduct() {
return Product;
}
public void setProduct(String product) {
Product = product;
}
public String getAge() {
return Age;
}
public void setAge(String age) {
Age = age;
}
}
table
SELECT "Year", "Product", "No.", "Age"
FROM "Products";
If you really want use the setters.
databaseStatus.setNo("No.");
databaseStatus.setYear( "Year");
databaseStatus.setProduct("Product");
databaseStatus.setAge("Age");
else remove the setters and
public class DatabaseStatus {
private String No = "No.";
private String Year = "Year";
private String Product = "Product";
private String Age = "Age";
public String getNo() {…
}

When I am entering search, the results are not displayed

LabServiceManagement.Java
package com.bean;
public class LabServiceManagement {
private String lspName;
private String address;
private int zipcode;
private String state;
private String city;
private String testName;
private int testCode;
private String testDescription;
private double costOfTest;
private String lab_home;
public String getLspName() {
return lspName;
}
public void setLspName(String lspName) {
this.lspName = lspName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getZipcode() {
return zipcode;
}
public void setZipcode(int zipcode) {
this.zipcode = zipcode;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getTestName() {
return testName;
}
public void setTestName(String testName) {
this.testName = testName;
}
public int getTestCode() {
return testCode;
}
public void setTestCode(int testCode) {
this.testCode = testCode;
}
public String getTestDescription() {
return testDescription;
}
public void setTestDescription(String testDescription) {
this.testDescription = testDescription;
}
public double getCostOfTest() {
return costOfTest;
}
public void setCostOfTest(double costOfTest) {
this.costOfTest = costOfTest;
}
public String getLab_home() {
return lab_home;
}
public void setLab_home(String lab_home) {
this.lab_home = lab_home;
}
}
DBUtility.java
package com.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBUtility {
static final String driver = "oracle.jdbc.driver.OracleDriver";
static final String dbURL = "jdbc:oracle:thin:#172.26.132.40:1521:ORCLILP";
static final String dbUserName = "aja16core";
static final String dbPassword = "aja16core";
public static Connection getConnection()
{
Connection con=null;
try {
// load the JDBC-ODBC Bridge driver
Class.forName(driver);
// connect to db using DriverManager
con = DriverManager.getConnection(dbURL, dbUserName, dbPassword);
}
catch (ClassNotFoundException | SQLException e)
{
e.printStackTrace();
}
return con;
}
public static void closeResultSet(ResultSet rs) {
if(rs!= null)
{
try
{
rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
public static void closeStatement(PreparedStatement ps) {
if(ps!= null)
{
try
{
ps.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
public static void closeConnection(Connection con) {
if(con!= null)
{
try
{
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}
LabServiceDAO.java
package com.dao;
import com.bean.LabServiceManagement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class LabServiceDAO {
public ArrayList<LabServiceManagement> searchcity(String city)
{
ArrayList<LabServiceManagement> result_list= new ArrayList<LabServiceManagement>();
Connection con=DBUtility.getConnection();
PreparedStatement ps=null;
ResultSet rs=null;
try
{
ps=con.prepareStatement("select * from LSP where CITY=? ");
ps.setString(1, city);
rs=ps.executeQuery();
while(rs.next())
{
String lspName=rs.getString("lspName");
String address=rs.getString("address");
int zipcode=rs.getInt("zipcode");
String state=rs.getString("state");
String testName=rs.getString("testName");
int testCode=rs.getInt("testCode");
String testDescription =rs.getString("testDescription");
double costOfTest=rs.getDouble("costOfTest");
String lab_home=rs.getString("lab_home");
LabServiceManagement l=new LabServiceManagement();
l.setLspName(lspName);
l.setAddress(address);
l.setZipcode(zipcode);
l.setState(state);
l.setCity(city);
l.setTestName(testName);
l.setTestCode(testCode);
l.setTestDescription(testDescription);
l.setCostOfTest(costOfTest);
l.setLab_home(lab_home);
result_list.add(l);
}
} catch (SQLException e)
{
e.printStackTrace();
}
finally
{
DBUtility.closeResultSet(rs);
DBUtility.closeStatement(ps);
DBUtility.closeConnection(con);
}
return result_list;
}
}
LabService.java
package com.service;
import java.util.ArrayList;
import com.bean.LabServiceManagement;
import com.dao.LabServiceDAO;
public class LabService {
public ArrayList<LabServiceManagement> searchcity(String city)
{
LabServiceDAO searchdao = new LabServiceDAO();
ArrayList<LabServiceManagement> result_list= searchdao.searchcity(city);
return result_list;
}
}
I have created table in SQL
I inserted few data
I coded for search city only, where I given mumbai which is already there in database, but result set is not coming
Can you please find the mistake, where I am gone wrong?

What is the logic of creating the Mysql SELECT Statement for drop down in Struts + JSP?

can you please help me rectify the code below, I'm trying to create a populated drop down list in struts 2 in Eclipse as my IDE. This is my first time to use 'STRUTS' as well as 'IDE ECLIPSE'.
To be specific by the SELECT statement I do not know how to write the code that, when a user selects the 'Make' of the car, the database extracts the different 'Models' of that make. But other select items like 'Color', should be optional in that a user can proceed to search for the 'Make' minus choosing an option from them.
Please help I'm new in ActionClass and DataBase. Thanx in advance.
package drive;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.opensymphony.xwork2.ActionSupport;
public class CarSearch extends ActionSupport {
private String model;
private String modification;
private String engine;
private String color;
private String bodyType;
private String minPrice;
private String maxPrice;
private String mileage;
private int minYear;
private int maxYear;
private String make;
public String execute () {
String ret = NONE;
Connection conn = null;
try {
String URL = "jdbc:mysql://localhost/Cars";
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(URL, "root", "$jademedia247");
String sql = "SELECT make FROM type WHERE";
sql+=" model = ? AND modification = ? ";
PreparedStatement ps = conn.prepareStatement (sql);
ps.setString(1, model);
ps.setString(2, modification);
ResultSet rs = ps.executeQuery();
while (rs.next()){
make = rs.getString(1);
ret = SUCCESS;
}
} catch (Exception e) {
ret = ERROR;
} finally {
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
}
}
}
return ret;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getModification() {
return modification;
}
public void setModification (String modification) {
this.modification = modification;
}
public String getEngine() {
return engine;
}
public void setEngine (String engine) {
this.engine = engine;
}
public String getColor() {
return color;
}
public void setColor (String color) {
this.color = color;
}
public String getBodyType() {
return bodyType;
}
public void setBodyType(String bodyType) {
this.bodyType = bodyType;
}
public String getMinPrice() {
return minPrice;
}
public void setMinPrice(String minPrice) {
this.minPrice = minPrice;
}
public String getMaxPrice () {
return maxPrice;
}
public void setMaxPrice (String maxPrice) {
this.maxPrice = maxPrice;
}
public String getMileage () {
return mileage;
}
public void setMileage (String mileage) {
this.mileage = mileage ;
}
public int getMinYear() {
return minYear;
}
public void setMinYear(int minYear) {
this.minYear = minYear;
}
public int getMaxYear() {
return maxYear;
}
public void setMaxYear(int maxYear) {
this.maxYear = maxYear;
}
public String getMake() {
return make;
}
public void setMake(String make){
this.make = make;
}
}
PreparedStatement ps = conn.prepareStatement ("SELECT field_name FROM table_name WHERE model = ? AND modification = ? ");
ps.setString(1, model);
ps.setString(2, modification);
ResultSet rs = ps.executeQuery();
//it will help you

Throws Exception in netbeans when using GET

I'm trying to retrieve data from my Model class into textfield via GET, although nullpointexception is throwing an error
The code in the View class is =
public View_EditCustomer(Model_Customer cust) {
customer = cust;
txtname.setText(customer.GetFName());
txtSecondName.setText(customer.GetLName());
initComponents();
}
and in another View class it is =
private void btnSelectActionPerformed(java.awt.event.ActionEvent evt) {
ListSelectionModel rowSM = jTable1.getSelectionModel();
int row = rowSM.getMinSelectionIndex();
int Appointment_ID = (Integer)resultModel.getValueAt(row, 0);
Model_Customer cust = null;
try{
cust = Controller_ManageCustomer.GetCustomer(Appointment_ID);
new View_EditCustomer(cust).setVisible(true);
}catch(Exception ex){
JOptionPane.showMessageDialog(this,ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
}
}
Model_Customer code parts =
public static Model_Customer QueryID(int Appointment_ID) throws Exception
{
try{
Statement stmt = Model_Customer.conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM appointment WHERE appointmentid="+Appointment_ID+" LIMIT 1;");
if(rs.next())
return new Model_Customer(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9),rs.getString(10),rs.getString(11),rs.getString(12));
}catch(Exception e){
throw new Exception(e.getMessage());
}
return null;
}
private Model_Customer(int Appointment_ID, String FName, String LName, String Registration, String Make, String Model, String Engine, String Year, String Mileage, String Type, String Date, String Time)
{
this._Appointment_ID=Appointment_ID;
this._Type=Type;
this._Time=Time;
this._Date=Date;
this._FName=FName;
this._LName=LName;
this._Make=Make;
this._Model=Model;
this._Engine=Engine;
this._Year=Year;
this._Mileage=Mileage;
this._Registration=Registration;
this._inSync=true;
}
public int GetID()
{
return this._Appointment_ID;
}
public String GetFName()
{
return _FName;
}
public String GetLName()
{
return _LName;
}
public String GetRegistration()
{
return _Registration;
}
public String GetMake()
{
return _Make;
}
public String GetModel()
{
return _Model;
}
public String GetEngine()
{
return _Engine;
}
public String GetYear()
{
return _Year;
}
public String GetMileage()
{
return _Mileage;
}
public String GetType()
{
return _Type;
}
public String GetDate()
{
return _Date;
}
public String GetTime()
{
return _Time;
}
In debugging Model_Customer cust is actually populated by data and it actually goes to the end to txtname.setText(customer.GetFName()); goes to Model_Customer GetFName and should retrieve the name but throws an exception (int)0. Would really appreciate your help!!
Shouldn't initComponents(); be called before using TextViews ?
public View_EditCustomer(Model_Customer cust) {
initComponents();
customer = cust;
txtname.setText(customer.GetFName());
txtSecondName.setText(customer.GetLName());
}

java.lang.NullPointerException when populating Jtextfield using a bean class

Here is my class which is a gui consisting of two tabs, my profile and edit profile. I am having a problem at the 'myProfileTabStateChanged' method when the index value changes to 1. When tab index is 0, 'myProfile()' method executes successfully, but when index is 1, 'editProfile()' is giving too many errors. The purpose of editprofile() is simply to extract the values from a bean class and set it to the textfields appropriately. What am I doing wrong? Please note the bean class variables are being populated correctly using setter methods, but in this class I am unable to retrieve the values using the getters? Perhaps it is retrieving but problem lies in being unable to set it to textfield.
public class MainMenu extends javax.swing.JFrame {
Academic ac = new Academic();
academicBean bn = new academicBean();
/**
* Creates new form MainMenu
*/
public MainMenu() {
initComponents();
// myProfile();
// editProfile();
}
public void myProfile() {
ac.retrieveAcademic();
nameLabel.setText(""+ac.title+" "+ac.forename+" "+ac.surname);
roleLabel.setText("Role: " + ac.role);
roomLabel.setText("Room: " + ac.room);
pageLabel.setText("Page: " + ac.page);
hoursLabel.setText("Hours: " + ac.hours);
phoneLabel.setText("Phone: " + ac.phone);
mobileLabel.setText("Mobile: " + ac.mobile);
emailLabel.setText("Email: " + ac.email);
imageLabel.setIcon(ac.format);
}
public void editProfile() {
ac.retrieveAcademic();
idLabel.setText("Academic Id: "+bn.getAcademicId());
txt_title.setSelectedItem(bn.getTitle().toString());
txt_fn.setText(bn.getForename().toString());
txt_ln.setText(bn.getSurname().toString());
combo_role.setSelectedItem(bn.getRole().toString());
txt_room.setText(bn.getRoom().toString());
txt_page.setText(bn.getPage().toString());
txt_hours.setText(bn.getHours().toString());
txt_phone.setText(bn.getPhone().toString());
txt_mobile.setText(bn.getMobile().toString());
txt_email.setText(bn.getEmail().toString());
}
private void myProfileTabStateChanged(javax.swing.event.ChangeEvent evt) {
JTabbedPane sourceTabbedPane = (JTabbedPane) evt.getSource();
int index = sourceTabbedPane.getSelectedIndex();
if (index == 0) {
myProfile();
}
else if (index == 1) {
editProfile();
}
}
//Class Academic
public class Academic extends javax.swing.JFrame {
String filename = null;
int s = 0;
byte[] person_image = null;
ImageIcon format = null;
LoginBean l = new LoginBean();
Connection con = javaconnect.ConnectDB();
academicBean bean = new academicBean();
PreparedStatement pst = null;
ResultSet rs = null;
int id;
String title;
String titleValue;
String forename;
String surname;
String role;
String roleValue;
String room;
String page;
String hours;
String phone;
String mobile;
String email;
byte[] imagedata = null;
public Academic() {
initComponents();
}
#SuppressWarnings("unchecked")
public void retrieveAcademic() {
try {
pst = con
.prepareStatement("SELECT * FROM AcademicInfo where Email=? and Password=?");
pst.setString(1, l.getUsername());
pst.setString(2, l.getPassword());
rs = pst.executeQuery();
while (rs.next()) {
id = (rs.getInt(1));
bean.setAcademicId(id);
title = (rs.getString(2));
bean.setTitle(title);
forename = (rs.getString(3));
bean.setForename(forename);
surname = (rs.getString(4));
bean.setSurname(surname);
role = (rs.getString(5));
bean.setRole(role);
room = (rs.getString(6));
bean.setRoom(room);
page = (rs.getString(7));
bean.setPage(page);
hours = (rs.getString(8));
bean.setHours(hours);
phone = (rs.getString(9));
bean.setPhone(phone);
mobile = (rs.getString(10));
bean.setMobile(mobile);
email = (rs.getString(11));
bean.setEmail(email);
imagedata = (rs.getBytes("Image"));
format = new ImageIcon(imagedata);
} // end while
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Academic.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pst != null) {
pst.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Academic.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
}
}
// Bean Class
public class AcademicBean {
private int academicid;
private String title;
private String forename;
private String surname;
private String role;
private String room;
private String page;
private String hours;
private String phone;
private String mobile;
private String email;
private byte [] image;
private String pass;
//Setters
public void setAcademicId (int academicid) {
this.academicid = academicid;
}
public void setTitle(String title) {
this.title = title;
}
public void setForename(String forename) {
this.forename = forename;
}
public void setSurname(String surname) {
this.surname = surname;
}
public void setRole(String role) {
this.role = role;
}
public void setRoom(String room) {
this.room = room;
}
public void setPage(String page) {
this.page = page;
}
public void setHours(String hours) {
this.hours = hours;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public void setEmail(String email) {
this.email = email;
}
public void setImage (byte [] image) {
this.image = image;
}
public void setPassword (String pass) {
this.pass= pass;
}
//Gettters
public String getPassword () {
return pass;
}
public int getAcademicId() {
return academicid;
}
public byte [] getImage() {
return image;
}
public String getTitle() {
return title;
}
public String getForename() {
return forename;
}
public String getSurname() {
return surname;
}
public String getRole() {
return role;
}
public String getRoom() {
return room;
}
public String getPage() {
return page;
}
public String getHours() {
return hours;
}
public String getPhone() {
return phone;
}
public String getMobile() {
return mobile;
}
public String getEmail() {
return email;
}
}
//Stacktrace
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.sqlite.PrepStmt.(PrepStmt.java:37)
at org.sqlite.Conn.prepareStatement(Conn.java:231)
at org.sqlite.Conn.prepareStatement(Conn.java:224)
at org.sqlite.Conn.prepareStatement(Conn.java:213)
at eecsCRM.Academic.retrieveAcademic(Academic.java:68)
at eecsCRM.MainMenu.editProfile(MainMenu.java:50)
at eecsCRM.MainMenu.myProfileTabStateChanged(MainMenu.java:569)
at eecsCRM.MainMenu.access$300(MainMenu.java:13)
at eecsCRM.MainMenu$4.stateChanged(MainMenu.java:194)
at javax.swing.JTabbedPane.fireStateChanged(JTabbedPane.java:400)
at javax.swing.JTabbedPane$ModelListener.stateChanged(JTabbedPane.java:253)
at javax.swing.DefaultSingleSelectionModel.fireStateChanged(DefaultSingleSelectionModel.java:116)
at javax.swing.DefaultSingleSelectionModel.setSelectedIndex(DefaultSingleSelectionModel.java:50)
at javax.swing.JTabbedPane.setSelectedIndexImpl(JTabbedPane.java:599)
at javax.swing.JTabbedPane.setSelectedIndex(JTabbedPane.java:574)
at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.mousePressed(BasicTabbedPaneUI.java:3628)
at javax.swing.plaf.synth.SynthTabbedPaneUI$1.mousePressed(SynthTabbedPaneUI.java:279)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:262)
at java.awt.Component.processMouseEvent(Component.java:6264)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4235)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Just a wild a***'d guess: You appear to have at least two completely unrelated academicBean objects (note that the class should be named AcademicBean), one in Academic, and one in MainMenu. I have a suspicion that they should be one and the same.
Perhaps MainMenu should have:
academicBean bn = ac.getAcademicBean();
and Academic have:
public academicBean getAcademicBean() {
return bean;
}
so that MainMenu can extract Academic's bean making the bean variables refer to one and the same bean object.

Categories