Velocity 的应用示例
private static void initJavaMail()
{
}
public static Connection getDatabaseConnection()
{
Connection con = null;
try
{
InitialContext initCtx = new InitialContext();
javax.naming.Context context = (javax.naming.Context) initCtx.lookup("java:comp/env");
javax.sql.DataSource ds = (javax.sql.DataSource) context.lookup("jdbc/TestDB");
//Utilities.debugPrintln("ds = " ds);
con = ds.getConnection();
}
catch (Exception e)
{
Utilities.debugPrintln("Exception = " e.getMessage());
return null;
}
//Utilities.debugPrintln("con = " con);
return con;
}
public static java.sql.ResultSet excuteDbQuery(Connection con, String sql,Object[] parameters)
{
//Exception err = null;
//Utilities.debugPrintln("excuteDbQuery" parameters[0] " ,sql=" sql);
try
{
java.sql.PreparedStatement ps = con.prepareStatement(sql);
for (int i = 0;
i <
parameters.length;
i )
{
processParameter(ps, i 1, parameters[i]);
}
return ps.executeQuery();
文章评论
共有位Admini5网友发表了评论 查看完整内容