Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

Hi, I was thinking how it it is possible to execute something like this with the help of JDBC as it presently provides an exception even if it is possible in the MySQL query browser.


While I realized that it is possible by having this SQL query string being split and getting the statement executed twice, but I was thinking if there is a single approach to this.

  String url = "jdbc:mysql://localhost:3306/";

    String dbName = "databaseinjection";

    String driver = "com.mysql.jdbc.Driver";

    String sqlUsername = "root"; 

    String sqlPassword = "abc";


   connection = DriverManager.getConnection(url+dbName, sqlUsername, sqlPassword);

1 Answer

0 votes
by (108k points)

Yes, you can do the execution in that manner. There are two possible ways to execute that kind of code:

1. Either you can set the database connection by allowing multiple queries, separated by a semi-colon by default.

2. Or you can call a stored procedure that will return the cursors implicitly.

For more information regarding the same, you can refer to the SQL training course.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.5k questions

29.9k answers


99.1k users

Browse Categories