我的第一个JDBC程序

2008年5月5日 | 分类: 后端语言 | 标签:

try { 
            Class.forName(”com.mysql.jdbc.Driver”);
            String connectionUrl1 = “jdbc:mysql://localhost/test?” +
                                   “user=root&password=admin”;
            Connection con = DriverManager.getConnection(connectionUrl1);
            System.out.println(”I have connect database”);
            Statement sm=con.createStatement();
             sm.executeUpdate(”delete from `test`.`test` where id=1″);
             sm.executeUpdate(”insert into `test`.`test` values(1,’Visual J++ Bible’,38)”);
            /*sm.executeUpdate(”insert into test”+”values(3,’java language’,40)”);*/
            sm.close();
            con.close();
        } catch (SQLException e) {
            System.out.println(”SQL Exception: “+ e.toString());
        } catch (ClassNotFoundException cE) {
            System.out.println(”Class Not Found Exception: “+ cE.toString());
        }

目前还没有任何评论.
注意: 评论者允许使用'@user:'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC:'(不包括单引号)将会自动将您的评论发送给ABC。请务必注意user必须和评论者名相匹配(大小写一致)。