{"id":183890,"date":"2024-11-10T08:35:20","date_gmt":"2024-11-10T00:35:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/183890\/"},"modified":"2024-11-10T08:35:21","modified_gmt":"2024-11-10T00:35:21","slug":"%e4%bd%bf%e7%94%a8netbeans%e6%93%8d%e4%bd%9cmysql%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/183890\/","title":{"rendered":"\u4f7f\u7528Netbeans\u64cd\u4f5cMySQL\u6578\u64da\u5eab"},"content":{"rendered":"<h1 id=\"%e4%bd%bf%e7%94%a8netbeans%e6%93%8d%e4%bd%9cmysql%e6%95%b8%e6%93%9a%e5%ba%ab-EojLnWsZOB\">\u4f7f\u7528Netbeans\u64cd\u4f5cMySQL\u6578\u64da\u5eab<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u8edf\u4ef6\u958b\u767c\u74b0\u5883\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u7ba1\u7406\u548c\u64cd\u4f5c\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002NetBeans\u4f5c\u70ba\u4e00\u500b\u5f37\u5927\u7684\u96c6\u6210\u958b\u767c\u74b0\u5883\uff08IDE\uff09\uff0c\u63d0\u4f9b\u4e86\u4fbf\u6377\u7684\u5de5\u5177\u4f86\u64cd\u4f5cMySQL\u6578\u64da\u5eab\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728NetBeans\u4e2d\u8a2d\u7f6e\u548c\u64cd\u4f5cMySQL\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9dmysql%e5%92%8cnetbeans-EojLnWsZOB\">\u5b89\u88ddMySQL\u548cNetBeans<\/h2>\n<p>\u9996\u5148\uff0c\u78ba\u4fdd\u4f60\u7684\u7cfb\u7d71\u4e2d\u5df2\u7d93\u5b89\u88dd\u4e86MySQL\u6578\u64da\u5eab\u548cNetBeans IDE\u3002\u4f60\u53ef\u4ee5\u5f9eMySQL\u7684\u5b98\u65b9\u7db2\u7ad9\u4e0b\u8f09\u4e26\u5b89\u88dd\u6700\u65b0\u7248\u672c\u7684MySQL Server\u3002\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u8a18\u5f97\u8a2d\u7f6e\u597d\u7528\u6236\u540d\u548c\u5bc6\u78bc\u3002<\/p>\n<p>\u63a5\u4e0b\u4f86\uff0c\u4e0b\u8f09\u4e26\u5b89\u88ddNetBeans IDE\u3002\u5b89\u88dd\u904e\u7a0b\u4e2d\uff0c\u9078\u64c7\u5305\u542bJava EE\u7684\u7248\u672c\uff0c\u4ee5\u4fbf\u80fd\u5920\u4f7f\u7528JDBC\u4f86\u9023\u63a5MySQL\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e9%85%8d%e7%bd%aemysql%e9%80%a3%e6%8e%a5-EojLnWsZOB\">\u914d\u7f6eMySQL\u9023\u63a5<\/h2>\n<p>\u5728NetBeans\u4e2d\uff0c\u4f60\u9700\u8981\u914d\u7f6eMySQL\u7684\u9023\u63a5\u3002\u4ee5\u4e0b\u662f\u5177\u9ad4\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li>\u6253\u958bNetBeans\uff0c\u9078\u64c7\u201cServices\u201d\u8996\u7a97\u3002<\/li>\n<li>\u53f3\u9375\u9ede\u64ca\u201cDatabases\u201d\uff0c\u9078\u64c7\u201cNew Connection\u201d\u3002<\/li>\n<li>\u5728\u5f48\u51fa\u7684\u5c0d\u8a71\u6846\u4e2d\uff0c\u9078\u64c7\u201cMySQL (Connector\/J driver)\u201d\u4f5c\u70ba\u6578\u64da\u5eab\u9a45\u52d5\u3002<\/li>\n<li>\u586b\u5beb\u9023\u63a5\u4fe1\u606f\uff0c\u5305\u62ec\u4e3b\u6a5f\u540d\uff08\u901a\u5e38\u662flocalhost\uff09\u3001\u7aef\u53e3\u865f\uff08\u9ed8\u8a8d\u70ba3306\uff09\u3001\u6578\u64da\u5eab\u540d\u7a31\u3001\u7528\u6236\u540d\u548c\u5bc6\u78bc\u3002<\/li>\n<li>\u9ede\u64ca\u201cTest Connection\u201d\u4ee5\u78ba\u4fdd\u9023\u63a5\u6210\u529f\uff0c\u7136\u5f8c\u9ede\u64ca\u201cFinish\u201d\u3002<\/li>\n<\/ol>\n<h2 id=\"%e5%89%b5%e5%bb%ba%e5%92%8c%e6%93%8d%e4%bd%9c%e6%95%b8%e6%93%9a%e5%ba%ab-EojLnWsZOB\">\u5275\u5efa\u548c\u64cd\u4f5c\u6578\u64da\u5eab<\/h2>\n<p>\u4e00\u65e6\u6210\u529f\u9023\u63a5\u5230MySQL\u6578\u64da\u5eab\uff0c\u4f60\u53ef\u4ee5\u958b\u59cb\u5275\u5efa\u548c\u64cd\u4f5c\u6578\u64da\u5eab\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684SQL\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab-EojLnWsZOB\">\u5275\u5efa\u6578\u64da\u5eab<\/h3>\n<pre><code>CREATE DATABASE my_database;<\/code><\/pre>\n<h3 id=\"%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab-EojLnWsZOB\">\u4f7f\u7528\u6578\u64da\u5eab<\/h3>\n<pre><code>USE my_database;<\/code><\/pre>\n<h3 id=\"%e5%89%b5%e5%bb%ba%e8%a1%a8-EojLnWsZOB\">\u5275\u5efa\u8868<\/h3>\n<pre><code>CREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(50) NOT NULL,\n    password VARCHAR(50) NOT NULL\n);<\/code><\/pre>\n<h3 id=\"%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-EojLnWsZOB\">\u63d2\u5165\u6578\u64da<\/h3>\n<pre><code>INSERT INTO users (username, password) VALUES ('admin', 'password123');<\/code><\/pre>\n<h3 id=\"%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-EojLnWsZOB\">\u67e5\u8a62\u6578\u64da<\/h3>\n<pre><code>SELECT * FROM users;<\/code><\/pre>\n<h3 id=\"%e6%9b%b4%e6%96%b0%e6%95%b8%e6%93%9a-EojLnWsZOB\">\u66f4\u65b0\u6578\u64da<\/h3>\n<pre><code>UPDATE users SET password = 'newpassword' WHERE username = 'admin';<\/code><\/pre>\n<h3 id=\"%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-EojLnWsZOB\">\u522a\u9664\u6578\u64da<\/h3>\n<pre><code>DELETE FROM users WHERE username = 'admin';<\/code><\/pre>\n<h2 id=\"%e4%bd%bf%e7%94%a8jdbc%e9%80%a3%e6%8e%a5mysql-EojLnWsZOB\">\u4f7f\u7528JDBC\u9023\u63a5MySQL<\/h2>\n<p>\u9664\u4e86\u4f7f\u7528NetBeans\u7684\u5716\u5f62\u754c\u9762\u64cd\u4f5c\u6578\u64da\u5eab\u5916\uff0c\u4f60\u9084\u53ef\u4ee5\u901a\u904eJava\u4ee3\u78bc\u4f7f\u7528JDBC\u4f86\u9023\u63a5\u548c\u64cd\u4f5cMySQL\u6578\u64da\u5eab\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>import java.sql.Connection;\nimport java.sql.DriverManager;\nimport java.sql.ResultSet;\nimport java.sql.Statement;\n\npublic class MySQLExample {\n    public static void main(String[] args) {\n        String url = \"jdbc:mysql:\/\/localhost:3306\/my_database\";\n        String user = \"root\";\n        String password = \"your_password\";\n\n        try {\n            Connection conn = DriverManager.getConnection(url, user, password);\n            Statement stmt = conn.createStatement();\n            ResultSet rs = stmt.executeQuery(\"SELECT * FROM users\");\n\n            while (rs.next()) {\n                System.out.println(\"User: \" + rs.getString(\"username\"));\n            }\n\n            conn.close();\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-EojLnWsZOB\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528NetBeans\u64cd\u4f5cMySQL\u6578\u64da\u5eab\u662f\u4e00\u500b\u7c21\u55ae\u800c\u6709\u6548\u7684\u904e\u7a0b\uff0c\u7121\u8ad6\u662f\u901a\u904e\u5716\u5f62\u754c\u9762\u9084\u662f\u7de8\u5bebJava\u4ee3\u78bc\uff0c\u90fd\u80fd\u5920\u8f15\u9b06\u5730\u9032\u884c\u6578\u64da\u5eab\u7684\u7ba1\u7406\u548c\u64cd\u4f5c\u3002\u9019\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u5c08\u6ce8\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u908f\u8f2f\uff0c\u800c\u4e0d\u5fc5\u904e\u591a\u64d4\u5fc3\u6578\u64da\u5eab\u7684\u7d30\u7bc0\u3002\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72\u4f60\u7684MySQL\u6578\u64da\u5eab\uff0c\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u9ad8\u6548\u7684\u6027\u80fd\u548c\u53ef\u9760\u7684\u6578\u64da\u5b58\u5132\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528Netbeans\u64cd\u4f5cMySQL\u6578\u64da\u5eab\uff0c\u638c\u63e1\u6578\u64da\u5eab\u9023\u63a5\u3001\u67e5\u8a62\u548c\u7ba1\u7406\u7684\u6280\u5de7\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-183890","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=183890"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183890\/revisions"}],"predecessor-version":[{"id":183891,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183890\/revisions\/183891"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=183890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=183890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=183890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}