JDBC Connection code to insert data using prepared statement.
import java.sql.*;
public class jdbc_insert
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:Darshana");
PreparedStatement ps=conn.prepareStatement("insert into Students
values(?,?,?,?,?)");
ps.setString(1,"4");
ps.setString(2,"Priyanka");
ps.setString(3,"Punjab");
ps.setString(4,"9877654321");
ps.setString(5,"Classic");
ps.executeUpdate();
ps.close();
conn.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
No comments:
Post a Comment