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();
  • 相关阅读:
    jquery 选择器总结
    jQuery 添加元素和删除元素
    jQuery 操作
    jquery 事件
    jQuery对象与DOM对象
    jquery 在页面中三种写法
    CSS3制作立体导航
    开发常用技巧之css字体编码
    c语言快速入门3
    c语言快速入门2
  • 原文地址:https://www.cnblogs.com/cy163/p/1272067.html
Copyright © 2011-2022 走看看