1. create a table in mysql name contact with
columns name,mobile,email,password
2.open bluej add reference library mysql-connector-java-5.1.13- bin.jar file if not available download from internet.
3.type the code given below. compile it and execute. Success.
import java.sql.DriverManager;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class test
{
public static void main(String args[])
{
String Name="SHIV SINGH";
String Mobile="9929760942";
String Email="s@gmail.com";
try
{
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection
("jdbc:mysql://localhost:3306/dbname","root", "dbpassword");
Statement stmt = (Statement) con.createStatement();
String query="INSERT INTO Contact VALUES('"+Name+"','"+Mobile+"','"+Email+"',password('abc'));";
stmt.executeUpdate(query);
System.out.println("Success");
}
catch(Exception e)
//this block is executed in case of an exception
{
//Display an error message in the dialog box for an exception
System.out.println(e.getMessage());
}
}
}
columns name,mobile,email,password
2.open bluej add reference library mysql-connector-java-5.1.13- bin.jar file if not available download from internet.
3.type the code given below. compile it and execute. Success.
import java.sql.DriverManager;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
public class test
{
public static void main(String args[])
{
String Name="SHIV SINGH";
String Mobile="9929760942";
String Email="s@gmail.com";
try
{
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection
("jdbc:mysql://localhost:3306/dbname","root", "dbpassword");
Statement stmt = (Statement) con.createStatement();
String query="INSERT INTO Contact VALUES('"+Name+"','"+Mobile+"','"+Email+"',password('abc'));";
stmt.executeUpdate(query);
System.out.println("Success");
}
catch(Exception e)
//this block is executed in case of an exception
{
//Display an error message in the dialog box for an exception
System.out.println(e.getMessage());
}
}
}
Comments
Post a Comment