写代码中的某一天,我写下了如下的代码:
publicConnection getConn() {
String driver= "com.mysql.jdbc.Driver";
String url= "***";
String username= "***";
String password= "***";
Connection conn= null;
PreparedStatement pst= null;try{
Class.forName(driver);//classLoader,加载对应驱动
conn =(Connection) DriverManager.getConnection(url, username, password);
String sql = "select * from info info , info_extend extend where info.id = extend.infoid "
+ " order by (CASE WHEN info.pid=1006 THEN 1 ELSE 0 END) asc ,(CASE WHEN info.pid = 1006 THEN info.intext ELSE extend.intext END) desc "
+ " limit 0,10";
System.out.println(sql);
pst = (PreparedStatement) conn.prepareStatement(sql);//准备执行语句 ResultSet rs = pst.executeQ