Books Related to Java Technology

Monday, January 5, 2009

JDBC Insert Query Example




import java.io.*;
import java.sql.* ;

class JDBCInsert{
public static void main( String args[] ){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbName","root", "root") ;
Statement stmt = conn.createStatement() ;
int rows = stmt.executeUpdate("INSERT INTO tableName VALUES (4, 'sandeep')");
System.out.println(rows + " Rows modified") ;
stmt.close() ;
conn.close() ;
} catch(SQLException se) {
System.out.println("SQL Exception:"+se) ;
} catch(Exception e){
System.out.println(e) ;
}
}
}

2 comments:

  1. This is the good example to understand for insert query......

    Good Blog

    ReplyDelete
  2. This is the good example to understand about jdbc insert query for java developers

    Good Blog for Java Programmer..

    I am appreciating you Nice...

    ReplyDelete