Advance Java Tutorial here : https://youtube.com/playlist?list=PLkx9f4H3tJMI4735IyPUp88bKCvatY2IY
DOWNLOAD MYSQL CONNECTOR FROM : http://www.java2s.com/Code/Jar/m/Downloadmysqlconnectorjar.htm
___________________________
INSERT RECORD IN JDBC - MYSQL EXAMPLE:
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bca", "root", "");
Statement st = (Statement) con.createStatement();
int i= st.executeUpdate("insert into register(uid,pass) values('avadh','tutor')");
if(i>0)
{
System.out.println("Success");
}
else
{
System.out.println("Not Success");
}
}
catch(Exception e)
{
System.out.println("Error"+e);
}
UPDATE RECORD INSIDE JDBC _ MYSQL:
try {
// TODO code application logic here
//Update Record Using JDBC
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bca","root","");
Statement st = (Statement)con.createStatement();
int i = st.executeUpdate("update register set mobile='90987565' where uid='avadh'");
if(i>0){
System.out.println("Update Success");
}
else{
System.out.println("Not Success");
}
} catch (SQLException ex) {
Logger.getLogger(UpdateRecord.class.getName()).log(Level.SEVERE, null, ex);
}
}
DELETE RECORD USING JDBC - MYSQL:
try {
// TODO code application logic here
//Update Record Using JDBC
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bca","root","");
Statement st = (Statement)con.createStatement();
int i = st.executeUpdate("delete from register where uid='avadh'");
if(i>0){
System.out.println("Delete Success");
}
else{
System.out.println("Not Success");
}
} catch (SQLException ex) {
Logger.getLogger(UpdateRecord.class.getName()).log(Level.SEVERE, null, ex);
}
}
How to Display Records inside JDBC MYSQL Example:
try{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = (java.sql.Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc_connect","root","");
Statement st = (Statement) con.createStatement();
//ResultSet Query
ResultSet rs = st.executeQuery("select * from feedback where id='"+i+"' ");
while(rs.next())
{
String id = String.valueOf(rs.getInt("id"));
String name = String.valueOf(rs.getString("name"));
String mobile = String.valueOf(rs.getString("mobile"));
String email = String.valueOf(rs.getString("email"));
String tbdata[] = {id,name,mobile,email};
//Add Table Data
tbmodel.addRow(tbdata);
}
}
catch(Exception e)
{
}
}
_____________________________
Advance java Tutorial Step by Step : https://youtube.com/playlist?list=PLkx9f4H3tJMI4735IyPUp88bKCvatY2IY
No comments:
Post a Comment