I am doing a simple program to connect MySQL database with Java, but the program throws the ClassCastException error.
This question says that Unsigned Bigint in MySQL is equivalent to long in Java.
Given below is the java part:
public static void main(String[] args) throws ClassNotFoundException, SQLException {
// TODO code application logic here
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql:///check1","uname","pwd");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from t1");
while(rs.next()){
System.out.println(rs.getObject(1)+ " "+ rs.getObject(2));
}
rs.close();
st.close();
con.close();
}
I am also including the schema for the table I created
mysql> desc t1;
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| rollno | bigint(20) | NO | PRI | NULL | auto_increment |
| name | varchar(40) | NO | | NULL | |
+--------+-------------+------+-----+---------+----------------+
2 rows in set (0.39 sec)