java - What is the best way/template to set up connection mysql and jdbc? -
What is the best way to set up a connection with mysql's jdbc? And execute simple statements. How to do it Thank you. The basic boilerplate for MySQL / JDBC is as follows:
class .for name ("com.mysql.jdbc.Driver"). NewInstance (); Connection conn = DriverManager.getConnection ("jdbc: mysql: // databaseName"); Execute the statement :
statement stmt = conn.createStatement (); Results reset rs = stmt.executeQuery ("select tagname" *); While (rsnext ()) {System.out.println (rs.getString (1)); } Close statements and connections :
rs.close (); Stmt.close (); Conn.close (); You need to make sure that you have the driver installed and / or your classmates.
Comments
Post a Comment