当前位置:网站首页>How to solve the problem of database content output
How to solve the problem of database content output
2022-07-02 15:10:00 【CSDN Q & A】
Why code one can run , Code two doesn't work
Code 1 javaimport java.sql.Connection;import java.sql.DriverManager;//import java.sql.Statement;import java.util.ArrayList;import com.mysql.jdbc.Statement;import java.sql.ResultSet;//import java.sql.SQLException;/** * * @author * */public class sql { ArrayList<Book> tushu=new ArrayList<>(); ArrayList<CD> b=new ArrayList<>(); ArrayList<Picture> c=new ArrayList<>(); Connection con=null; Statement st=null; public static void main(String[] args) throws Exception { // TODO Auto-generated method stub ResultSet rs=null; java.sql.Statement st=null; Connection con=null; Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/chengxusheji?useSSL=false","root","03579631"); st= con.createStatement(); String sql="select * from a"; rs=st.executeQuery(sql); while(rs.next()) { System.out.print(rs.getString(1)+"\t"); System.out.print(rs.getString(2)+"\t"); System.out.print(rs.getString(3)+"\t"); System.out.print(rs.getString(4)+"\t"); System.out.print(rs.getString(5)+"\t"); System.out.print(rs.getString(6)+"\t"); System.out.print(rs.getInt(7)+"\t"); System.out.print("\n"); } }} Code 2 java import java.util.ArrayList;import java.util.Scanner;import java.sql.*;import java.sql.Connection;import java.sql.DriverManager;//import java.sql.Statement;import com.mysql.jdbc.Statement;import java.sql.ResultSet;public class KSone { Scanner ad=new Scanner(System.in); ArrayList<Book> a=new ArrayList<>(); ArrayList<CD> b=new ArrayList<>(); ArrayList<Picture> c=new ArrayList<>(); /* * */ PreparedStatement ps1=null; PreparedStatement ps2=null; PreparedStatement ps3=null; String sql="insert into a values(?,?,?,?,?,?,?)"; String sql2="insert into b values(?,?,?,?,?,?,?)"; String sql3="insert into c values(?,?,?,?,?,?,?)"; /* * */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Scanner ad=new Scanner(System.in); KSone p=new KSone(); /* * Database definition */ Class.forName("com.mysql.jdbc.Driver"); Connection con=null; PreparedStatement ps1=null; PreparedStatement ps2=null; PreparedStatement ps3=null; con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/chengxusheji?useSSL=false","root","03579631"); String sql="insert into a values(?,?,?,?,?,?,?)"; String sql2="insert into b values(?,?,?,?,?,?,?)"; String sql3="insert into c values(?,?,?,?,?,?,?)"; ps1=con.prepareStatement(sql); ps2=con.prepareStatement(sql2); ps3=con.prepareStatement(sql3); /* * */ while(true) { System.out.println("*********** Media library management system *************"); System.out.println("\t1. Add items "); System.out.println("\t2. Query items "); System.out.println("\t3. Show inventory "); System.out.println("\t4. Edit item "); System.out.println("\t5. Delete items "); System.out.println("\t6. Statistics "); System.out.println("\t7. Storage of items "); System.out.println("\t8. Read items "); System.out.println("**********************************"); int s=ad.nextInt(); switch (s) { case 1: p.function1(); break; case 2: p.function2(); break; case 3: p.function3(); break; case 4: p.function4(); break; case 5: p.function5(); break; case 6: p.function6(); break; case 7: p.function7(); break; } } }//........public void function8() throws Exception { // ResultSet rs=null; java.sql.Statement st=null; Connection con=null; Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/chengxusheji?useSSL=false","root","03579631"); st= con.createStatement(); String sql="select * from a"; rs=st.executeQuery(sql); // ResultSet rs2=null; java.sql.Statement st2=null; st2= con.createStatement(); String sql2="select * from b"; rs2=st2.executeQuery(sql2); // ResultSet rs3=null; java.sql.Statement st3=null; st3= con.createStatement(); String sql3="select * from c"; rs3=st3.executeQuery(sql3); // while(rs.next()) { System.out.print(rs.getString(1)+"\t"); System.out.print(rs.getString(2)+"\t"); System.out.print(rs.getString(3)+"\t"); System.out.print(rs.getString(4)+"\t"); System.out.print(rs.getString(5)+"\t"); System.out.print(rs.getString(6)+"\t"); System.out.print(rs.getInt(7)+"\t"); System.out.print("\n"); } if (rs != null) { rs.close(); } if (st != null) { st.close(); } // while(rs2.next()) { System.out.print(rs2.getString(1)+"\t"); System.out.print(rs2.getString(2)+"\t"); System.out.print(rs2.getString(3)+"\t"); System.out.print(rs2.getString(4)+"\t"); System.out.print(rs2.getString(5)+"\t"); System.out.print(rs2.getString(6)+"\t"); System.out.print(rs2.getString(7)+"\t"); System.out.print("\n"); } if (rs2 != null) { rs2.close(); } if (st2 != null) { st2.close(); } // while(rs3.next()) { System.out.print(rs3.getString(1)+"\t"); System.out.print(rs3.getString(2)+"\t"); System.out.print(rs3.getString(3)+"\t"); System.out.print(rs3.getString(4)+"\t"); System.out.print(rs3.getString(5)+"\t"); System.out.print(rs3.getInt(6)+"\t"); System.out.print(rs3.getInt(7)+"\t"); System.out.print("\n"); } if (rs3 != null) { rs3.close(); } if (st3 != null) { st3.close(); } if (con != null) { con.close(); }}Operation results and error reporting contents
My solution ideas and tried methods
What I want to achieve
边栏推荐
- LeetCode 2320. Count the number of ways to place the house
- LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
- buuctf-pwn write-ups (7)
- 2021-2022学年编译原理考试重点[华侨大学]
- 學習使用php實現公曆農曆轉換的方法代碼
- Niuke Practice 101
- Some Chinese character codes in the user privacy agreement are not standardized, which leads to the display of garbled codes on the web page. It needs to be found and handled uniformly
- 871. 最低加油次数 : 简单优先队列(堆)贪心题
- btrace-(字节码)动态跟踪工具
- 数据分析常见的英文缩写(一)
猜你喜欢

Large top heap, small top heap and heap sequencing

LeetCode 209. Minimum length subarray

06_栈和队列转换
![[noi Simulation Competition] scraping (dynamic planning)](/img/ee/27a07f80207a2925f5065e633eb39f.png)
[noi Simulation Competition] scraping (dynamic planning)

08_ 串

数据分析思维分析方法和业务知识——业务指标

.NET Core 日志系统

Learn the method code example of converting timestamp to uppercase date using PHP

IE 浏览器正式退休

【C语音】详解指针进阶和注意点(2)
随机推荐
使用 TiUP 部署 TiDB 集群
Dragonfly low code security tool platform development path
Li Chuang EDA learning notes 15: draw border or import border (DXF file)
Why can't programmers who can only program become excellent developers?
LeetCode_滑动窗口_中等_395.至少有 K 个重复字符的最长子串
Topology architecture of the minimum deployment of tidb cluster
MFC timer usage
taobao. trade. Get (get some information of a single transaction), Taobao store order interface, Taobao oauth2.0 interface, Taobao R2 interface code docking and sharing
MFC 控制台打印,弹出对话框
Fundamentals of software testing
[untitled] leetcode 2321 Maximum score of concatenated array
C# 线程传参
tmall. product. schema. Get (product information acquisition schema acquisition), Taobao store upload commodity API interface, Taobao commodity publishing interface, Taobao commodity upload API interf
TiDB数据迁移场景综述
Tmall product details interface (APP, H5 end)
06_栈和队列转换
Map介绍
Socket and socket address
It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
LeetCode_字符串_简单_412.Fizz Buzz