| | |
| | | import java.util.Properties; |
| | | |
| | | import org.json.*; |
| | | import org.json.JSONArray; |
| | | |
| | | |
| | | public class DBHelper{ |
| | | |
| | | private String sqlurl="jdbc:mysql://10.153.19.150/gmms"; |
| | | private String sqlurl="jdbc:mysql://localhost/haier"; |
| | | private String user="root"; |
| | | private String password="beibo.123/"; |
| | | static java.util.Hashtable<String, DBHelper> helper=new java.util.Hashtable<String, DBHelper>(); |
| | |
| | | public class ProcResult{ |
| | | public int code; |
| | | public String Message; |
| | | public JSONArray Datas; |
| | | public org.json.JSONArray Datas; |
| | | } |
| | | |
| | | public static DBSession createDBSession(String name,boolean manulcomit) throws Exception{ |
| | |
| | | } |
| | | |
| | | |
| | | public JSONArray query(boolean asObject,String sql,Object...params) throws SQLException, JSONException{ |
| | | public org.json.JSONArray query(boolean asObject, String sql, Object...params) throws SQLException, JSONException{ |
| | | DBSession sn=null; |
| | | try{ |
| | | sn= createSession(false); |
| | |
| | | |
| | | |
| | | |
| | | public JSONArray query(String sql,Boolean RowAsObject,Object...params) throws SQLException, JSONException{ |
| | | public org.json.JSONArray query(String sql, Boolean RowAsObject, Object...params) throws SQLException, JSONException{ |
| | | DBSession sn=null; |
| | | try{ |
| | | sn=this.createSession(false); |
| | |
| | | |
| | | |
| | | |
| | | //锟斤拷锟斤拷一锟斤拷锟斤拷in锟斤拷锟斤拷 锟斤拷锟斤拷out锟斤拷锟斤拷锟侥存储锟斤拷锟教o拷一锟斤拷锟街讹拷锟斤拷int 1锟斤拷锟斤拷晒锟� 一锟斤拷锟斤拷String锟斤拷为一锟斤拷锟截革拷锟斤拷锟斤拷锟绞э拷锟绞憋拷锟轿拷锟绞撅拷锟较拷锟� |
| | | //锟斤拷锟斤拷一锟斤拷锟斤拷in锟斤拷锟斤拷 锟斤拷锟斤拷out锟斤拷锟斤拷锟侥存储锟斤拷锟教o拷一锟斤拷锟街讹拷锟斤拷int 1锟斤拷锟斤拷晒锟? 一锟斤拷锟斤拷String锟斤拷为一锟斤拷锟截革拷锟斤拷锟斤拷锟绞э拷锟绞憋拷锟轿拷锟绞撅拷锟较拷锟? |
| | | public QueryResult SelectByProc(String name,String[] Params){ |
| | | Connection con=null; |
| | | try{ |
| | |
| | | } |
| | | } |
| | | |
| | | //通锟斤拷一锟斤拷锟斤拷锟斤拷取锟斤拷锟捷硷拷锟斤拷锟� |
| | | //通锟斤拷一锟斤拷锟斤拷锟斤拷取锟斤拷锟捷硷拷锟斤拷锟? |
| | | public QueryResult getQueryResult(String sql){ |
| | | QueryResult query=null; |
| | | try{ |
| | |
| | | |
| | | |
| | | public static org.json.JSONArray resultToJson(String[] fields,ResultSet result,boolean RowAsObject) throws SQLException, JSONException{ |
| | | JSONArray arr=new JSONArray(); |
| | | org.json.JSONArray arr=new org.json.JSONArray(); |
| | | |
| | | String[] cols=fields; |
| | | |
| | |
| | | } |
| | | else{ |
| | | while(result.next()){ |
| | | JSONArray obj=new JSONArray(); |
| | | org.json.JSONArray obj=new org.json.JSONArray(); |
| | | for(int i=0;i<cols.length;i++){ |
| | | Object o=result.getObject(i+1); |
| | | if(o==null) |
| | |
| | | |
| | | //锟斤拷锟斤拷锟捷匡拷锟窖拷锟斤拷锟斤拷菁锟街憋拷锟阶拷锟轿狫sonArray, 锟斤拷锟絉owAsObject=true 每锟斤拷锟斤拷目锟斤拷锟斤拷锟斤拷为锟斤拷锟斤拷锟街讹拷锟斤拷锟斤拷jsonobject 锟斤拷锟斤拷每锟斤拷锟斤拷目锟斤拷锟斤拷一锟斤拷锟斤拷锟街讹拷锟斤拷锟斤拷 jsonarray锟斤拷锟斤拷 |
| | | public static org.json.JSONArray resultToJson(ResultSet result,boolean RowAsObject) throws SQLException, JSONException{ |
| | | JSONArray arr=new JSONArray(); |
| | | org.json.JSONArray arr=new org.json.JSONArray(); |
| | | ResultSetMetaData r= result.getMetaData(); |
| | | String[] cols=new String[r.getColumnCount()]; |
| | | |
| | |
| | | } |
| | | else{ |
| | | while(result.next()){ |
| | | JSONArray obj=new JSONArray(); |
| | | org.json.JSONArray obj=new JSONArray(); |
| | | for(int i=0;i<cols.length;i++){ |
| | | Object o=result.getObject(i+1); |
| | | if(o==null) |