Swing Saved Code:
=================================================try{
String url="jdbc:oracle:thin:@localhost:1521:orcl";
String username="hr";
String password="hr";
Connection con=DriverManager.getConnection(url, username, password);
Statement stmt=con.createStatement();
String Query;
Query = "INSERT INTO ALAMIN(ID,NAME,SALARY) VALUES('"+IDText.getText()+"','"+nameText.getText()+"','"+salaryText.getText()+"')";
stmt.execute(Query);
JOptionPane.showMessageDialog(null,"Employee entry ok");
}catch(SQLException ex){
JOptionPane.showMessageDialog(null, ex.toString());
IDText.setText(null);
nameText.setText(null);
salaryText.setText(null);
}
}
Data Retrive Using Eclipse From Database:
====================================================================package alamin;
import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class class_050116 {
public static void main(String[] args) {
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr");
java.sql.Statement st=con.createStatement();
String sql="select * from employees";
ResultSet rs=st.executeQuery(sql);
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2));
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Data Saved Using JSP:
===================================================<form action="insertData.jsp" action="post">
Name:<input type="text" name="name"><br>
fname:<input type=="text" name="fname"><br>
<input type="submit" value="send">
===================================================
<%@page import="java.sql.*"%>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr");
String name=request.getParameter("name");
String fname=request.getParameter("fname");
String sql="";
sql="insert into alamin values('"+name+"','"+fname+"')";
try{
Statement st=con.createStatement();
st.executeQuery(sql);
}catch(SQLException e)
{
out.print("NO DATA SAVED");
}
//con.close;
//con=null;
%>
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন