jsp连接Mysql关键代码

String url = "jdbc:mysql://localhost:3306/test";
   String user = "root";
   String password = "110";
   Connection conn = null;
   PreparedStatement pstmt = null;
   String driverName = "com.mysql.jdbc.Driver";
   try {

    Class.forName(driverName).newInstance();

    conn = DriverManager.getConnection(url, user, password);

   } catch (ClassNotFoundException e) {
    out.println(e);
   } catch (SQLException e) {
    out.println("连接SQLserver数据库失败!!!!!!");
   }

posted @ 2012-11-15 20:55  W&L  阅读(193)  评论(0编辑  收藏  举报