- package wsxk;
- import java.sql.*;
- public class ConDB{
- public static Connection init(){
- Connection conn = null;
- String url = "jdbc:odbc:xuanke";
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- try {
- conn= DriverManager.getConnection(url);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- return conn;
- }
- public ResultSet executeQuery(String sql)
- {
- ResultSet rs = null;
- try {
- rs = null;
- //System.out.println(url);
- Connection conn= this.init();
- //System.out.println(url);
- Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
- rs = stmt.executeQuery(sql);
- }
- catch (SQLException ex) {
- System.out.println("执行错误");
- ex.printStackTrace();}
- return rs;
- }
- public void executeUpdate(String strSQL)
- {
- try
- {
- Connection conn= this.init();
- Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
- 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 ;
- }
- public static void main(String args[]){
- ConDB c = new ConDB();
- }
- }