EDIT: I fixed the insert off by one mistake so I deleted that part of the question but still have the Bad value for type long error.
EDIT: the create statement for the small company table
create table small_company
(
first_name varchar(20),
last_name varchar(30),
address text,
emp_id serial not null
)
;
Created from:
create table company
(
first_name varchar(20),
last_name varchar(30),
company_name text,
address text,
city varchar(30),
province text,
postal varchar(7),
phone1 text,
phone2 text,
email text,
web text
)
;
create index name_priority
on company (first_name)
;
I'm getting this error saying "Bad value for type long :"
// insert values into the "small_company" table
long insertEmp(String first_name, String last_name, String address) {
String sql = "insert into small_company values (?,?,?)";
long id = 0;
try {
Connection conn = connect();
PreparedStatement pstmt = conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
pstmt.setString(1,first_name);
pstmt.setString(2,last_name);
pstmt.setString(3,address);
int affectedRows = pstmt.executeUpdate(); // returns number of affected rows
if (affectedRows > 0) { // means a row was affected so get the ID
try {
ResultSet rs = pstmt.getGeneratedKeys();
if (rs.next()) {
id = rs.getLong(1); // if cursor finds row with id, return it
}
}
catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
catch (SQLException e){
System.out.println(e.getMessage());
}
return id;
}
public static void main(String[] args) {
Queries q1 = new Queries();
//q1.getRowCount("company");
//q1.displayTable();
//q1.displayCompany(); // <- what I use to display table!
//q1.findEmployee(10);
q1.insertEmp("Laura","Lane","Daily St. Planet co. NE"); //<-what I use to insert!
}
All help is greatly appreciated!