我正在使用 Mysql JDBC 驱动程序.. 但我有一些问题..
问题是当我SELECT
在 java 源代码中使用 Query 时。
当我使用这个查询时:
select * from [name of table]
我已经成功地从数据库中获得了查询结果。
但是当我使用这个查询时:
select * from student where (substring(stu_name,0,1)>= '가' and substring(stu_name,0,1) < '나') ;
我还没有从数据库中得到查询结果..
不同之处在于使用where
与否。
有什么问题?
我怎么解决这个问题?
这是我下面的代码
此查询不起作用
select * from student where (substring(stu_name,0,1)>= '가' and substring(stu_name,0,1) < '나') ;
此查询运行良好
select * from student;
不同之处只是查询信息..其余的源代码绝对相同
我添加了我的 java 源代码 public class Center {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String sql = "select * from student where (substring(stu_name,0,1)>= '가' and substring(stu_name,0,1) < '나') ";
String url = "jdbc:mysql://localhost:3306/test";
String driverName = "com.mysql.jdbc.Driver";
String id = "root";
String password = "jsyun0415";
Connection con = null;
PreparedStatement prepareState = null;
Statement stmt = null;
ResultSet rs = null;
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> list_second = new ArrayList<String>();
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
System.out.println("Failed to load JDBC driver..");
e.printStackTrace();
return;
}
try {
con = DriverManager.getConnection(url, id, password);
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
list.add(rs.getNString("stu_no"));
list_second.add(rs.getNString("stu_ename"));
}
//test = list.get(2);
} catch (SQLException sqex) {
System.out.println("SQLException: " + sqex.getMessage());
System.out.println("SQLState: " + sqex.getSQLState());
} finally {
try {
if (stmt != null)
stmt.close();
if (con != null)
con.close();
if (rs != null)
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}