- 2

Can someone help me why these code can't run successfully in Netbeans? It's Data base connection and selection

//STEP 1. Import required packages import java.sql.*; public class JDBCExample { // JDBC driver name and database URL static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost/STUDENTS"; // Database credentials static final String USER = "username"; static final String PASS = "password"; public static void main(String[] args) { Connection conn = null; try{ //STEP 2: Register JDBC driver Class.forName("com.mysql.jdbc.Driver"); //STEP 3: Open a connection System.out.println("Connecting to a selected database..."); conn = DriverManager.getConnection(DB_URL, USER, PASS); System.out.println("Connected database successfully..."); }catch(SQLException se){ //Handle errors for JDBC se.printStackTrace(); }catch(Exception e){ //Handle errors for Class.forName e.printStackTrace(); }finally{ //finally block used to close resources try{ if(conn!=null) conn.close(); }catch(SQLException se){ se.printStackTrace(

31st Jan 2021, 11:16 PM
Rizalyn Sosing
Rizalyn Sosing - avatar
1 Antwort
0
Save your code in SoloLearn and share its link instead. As you can see, big code doesn't fit the limits of characters for a thread's Description, and therefore is truncated. Edit your Description and paste the saved code link over the truncated raw text code. Add error message description if there was any. Good luck! 👍 https://www.sololearn.com/post/75089/?ref=app
31st Jan 2021, 11:48 PM
Ipang