Can anyone tell why my program hangs
Posted by: 科峰 龙
Date: December 20, 2017 01:54AM

My codes are

=====================================
package com.enmoli.userservice;

import java.util.Date;
import java.util.UUID;
import java.util.zip.CRC32;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class CommonTest {

static Connection conn = null;

public static Connection getConnectionByJDBC() {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/inter", "abc", "abc");
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}

public static void test() {
String sql = "SELECT c.uid, b.grade as grade, b.score as score, b.normal_image as image, b2.score as scoreUp,"
+ " (b2.score - c.old_rank_beauty) as shortScore, b2.normal_image as nextImage"
+ " from cust_user_count c"
+ " left join shall_admin_user_grade_def b on c.rank_beauty=b.grade and b.type=1 and b.gender=0"
+ " left join shall_admin_user_grade_def b2 on b2.score<= c.old_rank_beauty and b2.score_up> c.old_rank_beauty and b2.type=1 and b2.gender=0"
+ " where c.uid = 68";
getConnectionByJDBC();
try {
Statement stmt = conn.createStatement();

//my program hang on the following line
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
String username = rs.getString("username");
String password = rs.getString("password");
System.out.println(username + "" + password);
}
} catch (SQLException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {

try {
if (conn != null)
conn.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}

public static void main(String[] args) {
CommonTest testjdbc = new CommonTest();
testjdbc.test();
}

}


=================================================

if I run my sql in mysql workbeach, it report a error "Error Code: 1690. BIGINT UNSIGNED value is out of range in '(`inter`.`b2`.`score` - '638733439')'"


I want to know why jdbc hangs rather than exit with error message?

How can I fix my code to let the program continue to run even the sql has some errors?

Options: ReplyQuote


Subject
Written By
Posted
Can anyone tell why my program hangs
December 20, 2017 01:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.