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:

Strong> Get connection :

  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

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -