zoukankan      html  css  js  c++  java
  • servlet 中 java 访问 Mysql 的代码示例

    Connection conn = null;
    String url="",QueryStr="";
    Statement stmt = null;
    ResultSet rs = null;

    String MySQL_IP = "192.180.15.1";
    String MySQL_ID = "mht";
    String MySQL_PW = "19951101";
    try{
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    // Class.forName("com.mysql.jdbc.Driver").newInstance();//使用这一行与上一行问题一样
    url ="jdbc:mysql://"MySQL_IP"/basic?user="MySQL_ID"&password="MySQL_PW"&useUnicode=true&characterEncoding=gb2312";
    conn = DriverManager.getConnection(url);
    stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    }catch(Exception e){
    e.printStackTrace();
    out.println(e);
    }
    String str="";
    QueryStr="select * from station where TYPE='0' or TYPE='1' or TYPE='2'";
    rs=stmt.executeQuery(QueryStr);
    while(rs.next()){
    str=rs.getString("STATION");
    out.print(str);
    }
    if(rs != null) rs.close();
    if(stmt != null) stmt.close();
    if(conn != null) conn.close();
  • 相关阅读:
    站立会议第七天
    站立会议第六天
    站立会议第五天
    站立会议第四天
    inotify简题
    搭建企业版yum仓
    ssh及ssh-key
    shell变量
    如何下载scp、wget、inotify及如何偷包
    rsync
  • 原文地址:https://www.cnblogs.com/cy163/p/1272067.html
Copyright © 2011-2022 走看看