connect java application to mysql server in netbeans 6.8 -


I'm starting in Java as well as Netbeen. Please enter the complete procedure that I can connect to mysql to my Java application

Download "mysql-connector-java-5.1.13-bin.jar" from the link

There is a sample Java code to connect to a monthly database and retrieve data from the table.

The code below is the database name "databasename"

and the name of the table is "YouTubeTable"

In the library of your Netbeen project "mysql-connector-java- Do not forget to add 5.1.13-bin.jar ".

  import java.sql .Connection; Import java.sql.DriverManager; Import java.sql.ResultSet; Import java.sql.Statement; Public square nuclass {public static zero main (string [] args) {connection conn = null; String url = "jdbc: mysql: //127.0.0.1: 3306 /"; String dbName = "databaseName"; Description stmt = null; Result result = null; String driver = "com.mysql.jdbc.Driver"; String databaseUsername = "root"; // database to connect to the database (plz replace it with your mysql username) string databasepassword = "root"; // password to connect to password (plz to change it with your mysql password) {class.forName (driver) .newInstance (); Conn = DriverManager.getConnection (url + dbName, databaseUserName, database password); Stmt = conn.createStatement (); Result = null; String password, user name; Results = stmt.executeQuery ("Select * from userTable '); If there was some data in the Else {// result set (; Result.isBeforeFirst ()) {System.out.println (" resultset no rows do not run "); Is .... ie some lines / process data in the table} are conn.close ();} hold (exception e) {e.printStackTrace ();}}}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -