From e4e6c1a0e34cbd5aca446018d19166497d8d7814 Mon Sep 17 00:00:00 2001 From: admin <52323@qq.com> Date: 星期五, 15 九月 2023 11:38:12 +0800 Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/CanadaMes --- springboot-vue3/src/main/java/com/example/springboot/service/JdbcConnections.java | 72 ++++++++++++++++++++++++++++++++++++ 1 files changed, 72 insertions(+), 0 deletions(-) diff --git a/springboot-vue3/src/main/java/com/example/springboot/service/JdbcConnections.java b/springboot-vue3/src/main/java/com/example/springboot/service/JdbcConnections.java new file mode 100644 index 0000000..5a5c756 --- /dev/null +++ b/springboot-vue3/src/main/java/com/example/springboot/service/JdbcConnections.java @@ -0,0 +1,72 @@ +package com.example.springboot.service; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.springframework.stereotype.Component; + +import com.example.springboot.entity.Glass; +@Component +public class JdbcConnections { + /** + * 鏁版嵁搴撹繛鎺ュ弬鏁� + * driver,url,username,password + */ + private static final String DRIVER = "com.mysql.jdbc.Driver"; + private static final String URL = "jdbc:mysql://localhost:3306/canadames"; + private static final String USERNAME = "root"; + private static final String PASSWORD = "beibo.123/"; + + private static Connection conn = null; + private static PreparedStatement ps = null; + private static ResultSet rs = null; + + public Glass selectGlass(int glassid) throws SQLException { + conn = getConn(); + Glass glass=new Glass(); + String sql = "select orderid from glass where glassid=?"; + ps = conn.prepareStatement(sql); + ps.setInt(1, glassid); + rs= ps.executeQuery(); + while (rs.next()) { + glass.setOrderId(rs.getShort("orderid")); + } + conn.close(); + return glass; + } + /** + * 1. 鍔犺浇椹卞姩 + * 2. 鑾峰彇杩炴帴 conn + * 3. 鍒涘缓璇彞 ps + * 4. 鎵ц璇彞 rs + * 5. 澶勭悊缁撴灉 + * 6. 鍥炴敹璧勬簮 + * + * 瀹炵幇CRUD + * 鏇存柊锛� + * 1澧炲姞 + * 2鍒犻櫎 + * 3淇敼 + * 鏌ヨ锛� + * 1. 鏌ヤ竴涓紝涓�涓璞� + * 2. 鏌ヤ竴缁勶紝鍋氭垚涓�涓璞″垪琛紝鏌ュ叏閮� + */ + public static Connection getConn() throws SQLException { + Connection conn = null; + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/canadames?serverTimezone=GMT%2B8&characterEncoding=utf-8", "root", "beibo.123/"); + return conn; + } + + static { + try { + Class.forName(DRIVER); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + +} -- Gitblit v1.8.0