RSS
热门关键字:  java  Ajax  JSP  JSF  Struts
当前位置 : 首页>JSP>列表

jdbc连接mysql

来源: 作者: 时间:2007-08-14 点击:
import java.sql.*;
public class TestJDBC {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            Class.forName( "com.mysql.jdbc.Driver" );
            //注册
            conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/scms" , "scms" , "scms" );
            st = conn.createStatement();
           
            st.executeUpdate( "INSERT INTO `menu` ( `parent_id` , `menu_name` , `menu_status` , `type` , `value` ) VALUES ( '0' , 'yeqing' , '1' , 'page' , '1' )" );
                   
            /*
            rs = st.executeQuery( "SELECT * FROM `menu`" );
           
            while ( rs.next() ) {
                System.out.println(rs.getString( "menu_name" ) );
            }
            */
        } catch ( ClassNotFoundException e ) {
            e.getStackTrace();
        } catch ( SQLException e ) {
            e.getStackTrace();
        } finally {
            try {
                if ( st != null ) {
                    st.close();
                    st = null;
                }
               
                if ( conn != null ) {
                    conn.close();
                    conn = null;
                }
            } catch ( SQLException e ) {
                e.getStackTrace();
            }
        }

    }

}

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
Google Adsense
相关文章