日期:2014-05-16 浏览次数:20489 次
class.forname("com.mysql.jdbc.driver");    string url = "jdbc:mysql://127.0.0.1/test?useunicode=true&characterencoding=utf-8";    string user = "";    string psw = "";    connection con = drivermanager.getconnection(url,user,psw);   com.mysql.jdbc.driver driver = new com.mysql.jdbc.driver(); //or: //new com.mysql.jdbc.driver(); string url = "jdbc:mysql://127.0.0.1/test?useunicode=true&characterencoding=utf-8"; string user = ""; string psw = ""; connection con = drivermanager.getconnection(url,user,psw);
com.mysql.jdbc.driver driver = null;    //or:    classloader cl = new classloader();    cl.loadclass("com.mysql.jdbc.driver");   package com.mysql.jdbc       public class driver extends nonregisteringdriver implements java.sql.driver {     // ~ static fields/initializers     // --------------------------------------------- //     // register ourselves with the drivermanager     //     static {        t ry {                  java.sql.drivermanager.registerdriver(new driver());              } catch (sqlexception e) {                  throw new runtimeexception("can't register driver!");              }      }    // ~ constructors     // -----------------------    /**     * construct a new driver and register it with drivermanager     *      * @throws sqlexception     *             if a database error occurs.     */    public driver() throws sqlexception {         // required for class.forname().newinstance()     }    }