| |

VerySource

 Forgot password?
 Register
Search
View: 2948|Reply: 15

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

[Copy link]

2

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-4 13:00:02
| Show all posts |Read mode
SQL="select"+name+"from aa";
The name is used to store the passed column name, if there are id, name, city, country... these columns in the aa table, but the two stored in the name may be city, country.
How to use re.getString("") to display it.
Reply

Use magic Report

0

Threads

16

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2021-3-4 13:15:01
| Show all posts
re.getString(1),
re.getString(2),
Reply

Use magic Report

2

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2021-3-4 13:30:02
| Show all posts
But it doesn’t have to be a few. It could be three or four
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Japan

Post time: 2021-3-4 15:15:01
| Show all posts
Take it all out and judge according to the conditions
Reply

Use magic Report

0

Threads

16

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2021-3-4 15:30:02
| Show all posts
kind of hard! ! ! If it is an ID, then using re.getString will still make an error
It’s better to judge the string NAME before querying the database. If the value of NAME is city, country, then use String[] to separate, name[0]="city",name[1]="country", then take it out to the database Then you can judge based on this
if(name[0].equals("city"))
{
String pstrcity=re.getString(1);
}
if(name[0].equals("country"))
{
String pstrcountry=re.getString(1);
}
Reply

Use magic Report

2

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2021-3-4 15:45: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.
Reply

Use magic Report

0

Threads

23

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2021-3-4 16:15:01
| Show all posts
If you know the select statement, you still don't know the column name? Reverse analysis of name.

In addition, your implementation is too bad. How can you directly link up the naked names like "city, country"?
You can pass a structure like String[] directly instead of name.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2021-3-4 16:30:02
| Show all posts
Get the column name through the result set
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2021-3-4 17: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
Reply

Use magic Report

0

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-4 17:15:01
| Show all posts
To give you an idea, write the NAME in an array, and then use a loop to fetch it when fetching it. That’s how I did it.
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