| |

VerySource

 Forgot password?
 Register
Search
Author: a2s1d2f1

How to display it on the web page when the column name is unknown?

[Copy link]

0

Threads

16

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2021-3-4 17:30:01
| Show all posts
select name,city,country from aa;
If this is the case, how to display it, the previous question is that I don’t know if it is name, city, country, these three items.
====================
Name, city, and country are in the name string
String[] name1=name.split(",");
such
name1[0] is name
name1[1] is city
name1[2] is country
Reply

Use magic Report

0

Threads

23

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2021-3-4 17:45:02
| Show all posts
Upstairs, name is equivalent to a string of data (similar to the toString() of an object), and reverse analysis is often a tedious and bad anti-pattern (unless there is a precise textual protocol definition). For example, if you directly name.split(",") does not guarantee success-consider spaces and quotation marks. So structured attribute parameters are the best way to force customers to specify a sequence of column names, such as the simplest array.
Reply

Use magic Report

0

Threads

11

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2021-3-4 18:00:01
| Show all posts
?

getMetaData
ResultSetMetaData getMetaData()
throws SQLException Retrieves the number, type, and attributes of the columns of this ResultSet object.

return:
A description of the columns of this ResultSet object
Throws:
SQLException-if a database access error occurs
------------------------------------


This is a positive solution
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Great Britain

Post time: 2021-3-4 18:15:01
| Show all posts
Can I rename it?
select "+name+" as mydate1 from aa";
rs.getstring("mydate1")
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2021-3-4 18:30:01
| Show all posts
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData rsm = rs.getMetaData();
String[] cols = new String[rsm.getColumnCount()];
for (int i = 0; i <cols.length; i++)
cols[i] = rsm.getColumnName(i + 1);
Reply

Use magic Report

1

Threads

2

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2021-8-14 21:58:32
| Show all posts
A little wired, could you change your demandes?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list