JSP+Oracle数据库组建动态网站经典实例
源代码在线查看: jdbcodbc_con.java
package sts;
import java.sql.*;
public class JdbcOdbc_Con
{
String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String strCon = "jdbc:odbc:sts";
Connection con = null;
ResultSet rs = null;
Statement stmt = null;
public JdbcOdbc_Con()
{
try
{
Class.forName(dbDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("数据库驱动程序加载失败,异常为:" + e.getMessage());
}
finally
{
System.out.println("驱动程序加载成功");
}
}
public ResultSet executeQuery(String strSQL)
{
rs = null;
try
{
con = DriverManager.getConnection(strCon);
Statement stmt = con.createStatement();
rs = stmt.executeQuery(strSQL);
}
catch(SQLException ex)
{
System.err.println("连接数据库失败了,异常为:" +ex.getMessage());
}
finally
{
System.out.println("数据库连接成功");
}
return rs;
}
public void executeUpdate(String strSQL)
{
try
{
con = DriverManager.getConnection(strCon);
stmt = con.createStatement();
stmt.executeQuery(strSQL);
}
catch(SQLException ex)
{
System.err.println("连接数据库失败了,异常为:" +ex.getMessage());
}
}
public String ex_chinese(String str)
{
if(str==null)
{
str ="" ;
}
else
{
try
{
str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
}
catch (Exception ex)
{
System.err.println("异常为:" +ex.getMessage());
}
}
return str ;
}
public String gettime()
{
String datestr = "" ;
try
{
java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy年MM月dd日 HH点ss分") ;
java.util.Date date = new java.util.Date() ;
datestr = df.format(new java.util.Date()) ;
}
catch (Exception ex)
{
System.err.println("异常为:" +ex.getMessage());
}
return datestr ;
}
}