📄 otherutil.java
字号:
package com.sxit.wap.common;
import java.sql.*;
import java.util.*;
import com.sxit.wap.common.*;
import com.sxit.wap.exception.*;
import com.sxit.wap.user.*;
public class OtherUtil {
public static long LONG_MAX_VALUE = 4294967295L;
public static int DATABASE_ERROR = 0;
public static int NO_TABLES_ERROR = 1;
public static int NO_DATA_ERROR = 2;
public static int NO_ERROR = 3;
public static float format(float f) {
return (float)Math.round(f*100)/100;
}
public static int testDatabase() throws SysException {
String sql = "SELECT * FROM " + UserBean.tableName;
Connection dbConnection = null;
Statement stmt = null;
ResultSet rs = null;
try {
try {
dbConnection = getDBConnection();
} catch (Exception e) {
return OtherUtil.DATABASE_ERROR;
}
try {
stmt = dbConnection.createStatement();
rs = stmt.executeQuery(sql);
if (!rs.next() ) {
return OtherUtil.NO_DATA_ERROR;
} else {
return OtherUtil.NO_ERROR;
}
} catch (Exception e) {
return OtherUtil.NO_TABLES_ERROR;
}
} finally {
closeResultSet(rs);
closeStatement(stmt);
closeConnection(dbConnection);
}
}
private static Connection getDBConnection() throws SysException {
return Database.getConnection();
}
private static void closeConnection(Connection dbConnection) throws SysException {
try {
if (dbConnection != null && !dbConnection.isClosed()) {
dbConnection.close();
dbConnection = null;
}
} catch (SQLException se) {
//throw new SysException("SQL Exception while closing DB connection : \n" + se);
}
}
private static void closeResultSet(ResultSet result) throws SysException {
try {
if (result != null) {
result.close();
}
} catch (SQLException se) {
//throw new SysException("SQL Exception while closing Result Set : \n" + se);
}
}
private static void closeStatement(Statement stmt) throws SysException {
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException se) {
//throw new SysException("SQL Exception while closing Statement : \n" + se);
}
}
public static int getPortByUrl(String url) {
int i = url.indexOf(":");
String temp = url.substring(i + 1);
i = temp.indexOf(":");
if (i == -1) return 80;
temp = temp.substring(i + 1);
i = temp.indexOf("/");
if (i == -1) return Integer.parseInt(temp);
return Integer.parseInt(temp.substring(0, i));
}
public static void main(String[] args) throws Exception {
System.out.println(OtherUtil.getPortByUrl("http://www.wqsoft.com:8090"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -