📄 databaseutils.java
字号:
package com.skyhawk.db;
import java.sql.*;
public class DatabaseUtils
{
public static void closeObject(ResultSet rs, Statement stm, Connection con)
{
closeObject(rs);
closeObject(stm, con);
}
public static void closeObject(Statement stm, Connection con)
{
closeObject(stm);
closeObject(con);
}
public static void closeObject(Connection con)
{
//release the connection
try
{
if (con != null)
{
con.close();
}
} catch (Exception e)
{
}
}
public static void closeObject(ResultSet rs)
{
//release the resultset
try
{
if (rs != null)
{
rs.close();
}
} catch (Exception e)
{
}
}
public static void closeObject(Statement st)
{
//release the statement
try
{
if (st != null)
{
st.close();
}
} catch (Exception e)
{
}
}
public static long getNextId(Connection con, String sequence)
{
Statement st = null;
ResultSet rs = null;
long nextId = 1;
try
{
st = con.createStatement();
rs = st.executeQuery("select " + sequence + ".nextval as id from dual");
rs.next();
nextId = rs.getLong(1);
} catch (Exception e)
{
e.printStackTrace();
} finally
{
closeObject(rs, st, null);
}
return nextId;
}
public static Date getCurrentDate(Connection con) throws SQLException
{
String strSQL = " SELECT sysdate as datevalue FROM dual";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(strSQL);
rs.next();
Date dtRtn = rs.getDate(1);
closeObject(rs, st, null);
return dtRtn;
}
public static void main(String[] args) throws Exception
{
//long nextId = DatabaseUtils.getNextId(ConnectionFactory.getConnection(), "student_seq");
//System.out.println(nextId);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -