// java database connectivity
import java.sql.*;class database_connectivity
{
Connection con=null;
Statement stmt=null;
database_connectivity()
{
try{
Class.forName("com.mysql.jdbc.Driver");
con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/ict","root","admin");
//JOptionPane.showMessageDialog( "cool");
System.out.println("Connected");
stmt=(Statement) con.createStatement();
}catch(Exception e)
{
System.out.println(e);
}
//now inserting data into emp table
int id=Integer.parseInt(txt1.getText());100;
String name="abcd";
double salary=40000;
try{
for(int i=1;i<5;i++)
// String sql=;
{
stmt.executeUpdate("insert into emp values("+i+",'"+name+"',"+salary+")");
}
System.out.println("Successfully Inserted.");
}catch(Exception ee)
{
System.out.println(ee);
}
}
public static void main(String[] arg)
{
database_connectivity cc=new database_connectivity();
}
}
No comments:
Post a Comment