Created
July 4, 2017 10:26
-
-
Save nitishk72/04eafa9cd4b3be0a4595cf3afdd06b29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
/* | |
* @author nitish | |
*/ | |
public class Database { | |
public static void main(String[] args) { | |
try{ | |
Class.forName("com.mysql.jdbc.Driver"); | |
Connection con=DriverManager.getConnection( | |
"jdbc:mysql://localhost:3306/dbname","root",""); | |
Statement stmt=con.createStatement(); | |
String sql = "INSERT INTO tablename " +"VALUES ('Java Programmer');"; | |
stmt.executeUpdate(sql); | |
con.close(); | |
}catch( ClassNotFoundException | SQLException e){ | |
System.out.println(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment