2, try {Class. forName (driverName); dbConnDriverManager. getConnection (dbURL, userName, userPwd); StatementstdbConn. createStatement (); Create an SQL statement object Stringsgselect * cuteQuery (sg );
2, try {Class. forName (driverName); dbConn = DriverManager. getConnection (dbURL, userName, userPwd); Statement st = dbConn. createStatement (); // create an SQL statement object String sg = select * from Student; // query the Student table ResultSet rs1_st.exe cuteQuery (sg );/
2,
Try {Class. forName (driverName); dbConn = DriverManager. getConnection (dbURL, userName, userPwd); Statement st = dbConn. createStatement (); // create an SQL statement object String sg = "select * from Student"; // query the Student table ResultSet rs1_st.exe cuteQuery (sg); // execute the SQL command, the returned result set is ResultSet while (rs. next () // move the pointer to the next record {System. out. println (rs. getString ("id") + "\ t" + rs. getString ("name") + "\ t" + rs. getString ("phone"); // output query record format} st. close ( ); DbConn. close (); System. out. println ("Connection Successful! 132 "); // If the Connection is Successful, the console outputs Connection Successful! } Catch (Exception e) {e. printStackTrace ();}
2. (1) when executing an SQL statement, use executeQuery (String) to process queries or add records );
(2) Use executeUpdate (String) to process modification or deletion records );
3. When closing, close the Statement class object and then close the connection.
St. close ();
DbConn. close ();