Native JDBC links are generally divided into 7 steps to get links and execute SQL statements
1, prepare 4 key parameters
Static { "jdbc:mysql://localhost:3306/test" ; " Com.mysql.jdbc.Driver " ; " Root " ; " Root " ; }
2, registered Driver
new Com.mysql.jdbc.Driver ());
3, get links
Connect = drivermanager.getconnection (URL, userName, password);
4, Execute SQL statement
" SELECT * from Sys_user " ; = connect.preparestatement (SQL);
5, get the result set
ResultSet = State.executequery ();
6, Result set processing
while (Resultset.next ()) { = resultset.getstring ("name"); = Resultset.getstring (2); System. out " " + Sex); }
7, close the connection
if(ResultSet! =NULL) { Try{resultset.close (); } Catch(SQLException e) {e.printstacktrace (); } } if(state! =NULL) { Try{state.close (); } Catch(SQLException e) {e.printstacktrace (); } } if(Connect! =NULL) { Try{connect.close (); } Catch(SQLException e) {e.printstacktrace (); } }
sql-Native JDBC Connection 7 steps