You are on page 1of 2

wamp/mysql/bin

lab section
example one
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/rift","root","");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into student values ('daniel',34,78978)");
System.out.println("data is inserted ");
con.close();

example
update student set salary =90909 where name='daniel'

example 2

Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/rift","root","");
PreparedStatement pstmt=con.prepareStatement("insert into student values
(?,?,?)");
Scanner sc=new Scanner(System.in);
System.out.println("enter ur name ");
String name=sc.nextLine();
System.out.println("pls enter ur age");
int age=sc.nextInt();
System.out.println("pl enter ur salary ");
float salary =sc.nextFloat();
pstmt.setString(1, name);
pstmt.setInt(2, age);
pstmt.setFloat(3, salary);
int ii=pstmt.executeUpdate();
System.out.println(ii+"row is inserted ");
pstmt.close();
con.close();

example 3

Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/rift","root","");
PreparedStatement pstmt=con.prepareStatement("");
ResultSet rs=pstmt.executeQuery("select * from student");
while(rs.next())
{
System.out.println(rs.getString(1)+" "+rs.getObject(2)+" "+rs.getString(3));
}

example 4

servlet class
out.println("<h1> <i>Rift Main main campus </i></h1>");

out.println("<hr>");
out.println("<p> we can register the memebership of the student </p>");
web.xml

<servlet>
<servlet-name>first</servlet-name>
<servlet-class>example</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>first</servlet-name>
<url-pattern>/first</url-pattern>
</servlet-mapping>

You might also like