-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathInsertRecord.java
More file actions
32 lines (31 loc) · 878 Bytes
/
InsertRecord.java
File metadata and controls
32 lines (31 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class InsertRecord extends HttpServlet{
public void doGet(HttpServletRequest request,
HttpServletResponse response)throws
ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String url ="jdbc:mysql://localhost:3306/mydb";
Connection conn;
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url,"root","onishi1313");
Statement statement = conn.createStatement();
String query = "insert into bit values(110,'Yash Mehta','CSE')";
int i = statement.executeUpdate(query);
if(i!=0){
out.println("The record has been inserted");
}
else{
out.println("Sorry! Fail to Insert");
}
statement.close();
}
catch (Exception e){
System.out.println(e);
}
}
}