0

I'm writing a Java tool to parse SQL Queries in order to get table and columns details. To parse SELECT statement I use MySQL JDBC ResultSetMetaData. Something like :

 String query = "select * from vendors";
 PreparedStatement pstmt = con.prepareStatement(query);
 ResultSetMetaData meta = pstmt.getMetaData();
 System.out.println(meta);

But this doesn't work for INSERT/UPDATE statement.

Does someone have a solution to do that?

I tried various other solutions without success.

Thanks

1

1 Answer 1

0

you can get the column name of the table using ResultsSetMetaData like this,

  ResultSetMetaData rsmd=res.getMetaData();
  int columnCount=rsmd.getColumnCount();
  for (int i = 1; i<= columnCount; i++) {
    columnHeading=columnHeading+"\t"+rsmd.getColumnName(i);

  System.out.println(columnHeading);
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, Thanks for your answer. But your solution (what i've already made) doesn't work with INSERT/UDPDATE/DELETE statements.
search some online tutorials just like, come2niks.com/jdbc-insert-update-and-delete-example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.