Skip to content

Instantly share code, notes, and snippets.

@nitishk72
Created July 4, 2017 10:26
Show Gist options
  • Save nitishk72/04eafa9cd4b3be0a4595cf3afdd06b29 to your computer and use it in GitHub Desktop.
Save nitishk72/04eafa9cd4b3be0a4595cf3afdd06b29 to your computer and use it in GitHub Desktop.
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