Wednesday, 11 December 2013

inserting into the table using url

//connecting to the db using url
import java.sql.*;//jdbc api
class jdbcdemo
{

public static void main(String[] args) throws Exception
{

//Class.forName("oracle.jdbc.driver.OracleDriver");
//Connection conn = DriverManager.getConnection("jdbc:odbc:oracleXE","sai","sai");
//Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","sai","sai" );
//loading the jdbc driver
Class.forName("com.mysql.jdbc.Driver");

//establish the connection with db sw
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "admin");

Statement st= con.createStatement();

st.executeUpdate("insert into emp values(20,'sai',200)");
System.out.println("Rows inserteded");
st.close();
con.close();

}



}
/*
D:\jdbc>set classpath=D:\softwares\MySQL\new\mysql-connector-java-5.1.18-bin.jar;.;
D:\jdbc>javac jdbcdemo2.java
D:\jdbc>java jdbcdemo2
*/

No comments:

Post a Comment