{"id":411,"date":"2017-02-06T09:40:38","date_gmt":"2017-02-06T01:40:38","guid":{"rendered":"http:\/\/www.rainweb.site\/?p=411"},"modified":"2023-08-07T20:57:30","modified_gmt":"2023-08-07T12:57:30","slug":"java-article27","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2017\/02\/06\/java-article27\/","title":{"rendered":"Java\u4f7f\u7528mysql\u6570\u636e\u5e93\u5b9e\u73b0\u589e\u5220\u6539\u67e5"},"content":{"rendered":"<h3>\u6211\u5728\u535a\u5ba2\u91cc\u6709\u4e00\u7bc7\u300aJava\u4f7f\u7528jdbc\u8fde\u63a5\u6570\u636e\u5e93\u300b\uff0c\u8fde\u63a5\u6210\u529f\u4ee5\u540e\u5c31\u9700\u8981\u5bf9\u6570\u636e\u5e93\u8fdb\u884c\u64cd\u4f5c\uff0c\u4eca\u5929\u8fd9\u7bc7\u535a\u6587\u4e3b\u8981\u4ecb\u7ecd\u6211\u5728Java\u4e2d\u7ecf\u5e38\u7528\u5230\u7684\u6570\u636e\u5e93\u64cd\u4f5c\uff0c\u53ea\u6311\u6700\u5e38\u7528\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/h3>\n<h3>\u4e00.\u67e5\u627e<\/h3>\n<pre><code class=\"java\">public String getC_name(int c_id) {\n        \/\/ TODO Auto-generated method stub\n        String c_name=\"\";\n        Connection conn = DBUtil.getConnectDb();\n        String sql=\"select * from customer where c_id=?\";\n        try {\n            PreparedStatement stm = conn.prepareStatement(sql);\n            stm.setInt(1, c_id);\n            ResultSet rs = stm.executeQuery();\n            if(rs.next())\n            {\n                c_name = rs.getString(\"c_name\");\n            }\n        } catch (SQLException e) {\n            \/\/ TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n\n        return c_name;\n    }\n<\/code><\/pre>\n<h3>\u4e8c.\u4fee\u6539<\/h3>\n<pre><code class=\"java\">public void is_loginInfo(int m_id,int is_login)\n    {\n        Connection conn = DBUtil.getConnectDb();\n        String sql=\"update manager set is_login=? where m_id=?\";\n        PreparedStatement stm = null;\n        try {\n            stm = (PreparedStatement) conn.prepareStatement(sql);\n\n            is_login=(is_login==1?0:1);\n\/\/            System.out.println(is_login);\n            stm.setInt(1, is_login);\n            stm.setInt(2, m_id); \n            stm.executeUpdate();\n        } catch (SQLException e) {\n            \/\/ TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n\n    }\n<\/code><\/pre>\n<h3>\u4e09.\u63d2\u5165<\/h3>\n<pre><code class=\"java\">public int insertProduct(ProductBean item) {\n        \/\/ TODO Auto-generated method stub\n        Connection conn = DBUtil.getConnectDb();\n        String sql=\"insert into product(p_name,p_money,p_totalnum,p_desc,back_money,p_id) values(?,?,?,?,?,?)\";\n        int rs = 0;\n        try {\n            PreparedStatement stm = conn.prepareStatement(sql);\n            stm.setString(1, item.getP_name());\n            stm.setInt(2, item.getP_money());\n            stm.setInt(3, item.getP_totalnum());\n            stm.setString(4, item.getP_desc());\n            stm.setInt(5, item.getBack_money());\n            stm.setInt(6, item.getP_id());\n            rs = stm.executeUpdate();\n        } catch (SQLException e) {\n            \/\/ TODO Auto-generated catch block\n            e.printStackTrace();\n        }\n        return rs;\n    }\n<\/code><\/pre>\n<h3>\u56db.\u5220\u9664<\/h3>\n<pre><code class=\"java\">public static void main(String[] args)\n    {\n        Connection conn = DBUutil.getConnectDb();\n        String sql=\"delete from user where name='scs'\";\n        PreparedStatement stm = null;\n        ResultSet rs = null;\n        int rss=0;\n        try {\n\n            stm = conn.prepareStatement(sql);\n            rss=stm.executeUpdate(sql);\n            System.out.println(rss);\n\n        } catch (SQLException e) {\n            \/\/ TODO: handle exception\n            e.printStackTrace();\n        }\n        finally\n        {\n            DBUutil.CloseDB(rs,stm,conn);\n        }\n    }\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u5728\u535a\u5ba2\u91cc\u6709\u4e00\u7bc7\u300aJava\u4f7f\u7528jdbc\u8fde\u63a5\u6570\u636e\u5e93\u300b\uff0c\u8fde\u63a5\u6210\u529f\u4ee5\u540e\u5c31\u9700\u8981\u5bf9\u6570\u636e\u5e93\u8fdb\u884c\u64cd\u4f5c\uff0c\u4eca\u5929\u8fd9\u7bc7\u535a\u6587\u4e3b\u8981\u4ecb\u7ecd\u6211\u2026 <span class=\"read-more\"><a href=\"http:\/\/rain1024.com\/index.php\/2017\/02\/06\/java-article27\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":412,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[31],"tags":[46,56],"class_list":["post-411","post","type-post","status-publish","format-aside","has-post-thumbnail","hentry","category-java","tag-java","tag-mysql","post_format-post-format-aside"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=411"}],"version-history":[{"count":1,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/411\/revisions"}],"predecessor-version":[{"id":1513,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/411\/revisions\/1513"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media\/412"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=411"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}