
I have written the code to query the database to retrieve the flight details and the schedule of the flights, however, when executing the code i experience an error which says Error :java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified. can you please identify and state the reason behind this error. In addition, provide the correct solution for the same. The code is as follows:
import java.sql.*; public class Test { public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:air_dsn", "sa", "pass@123"); Statement stat = con.createStatement(); ResultSet rs = stat.executeQuery("select flno,flroute, dp_timings from schedule"); System.out.println("* Flight Schedule ***"); while (rs.next()) System.out.print(rs.getString(1) + " : " + rs.getString(2)+ " : "+rs.getString(3) + "\n"); con.close(); con = DriverManager.getConnection("jdbc:odbc:air_dsn","sa", "pass@123"); rs = stat.executeQuery("select flno,aircrafttype,seating_capacity from Flights"); System.out.println("* Flight Details ***"); while (rs.next()) System.out.print(rs.getString(1) + " : " + rs.getString(2)+ " : "+rs.getInt(3) + "\n"); con.close(); } catch (Exception e) { System.out.println("Error :"+e); } } }

Set up DSN connection
Follow these steps:
1)Go to the start<<Control Panel<<Administrative Tools<< data sources.
2)Click Add button and select the driver Microsoft Access Driver(*.mdb).
3)After selecting the driver, click finish button.
4)Then give Data Source Name and click ok button.
5)Your DSN will get created.
6) Restart your command prompt and compile your java code.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.