import java.sql.*;
public class ramu{
public static void main(String args[]){
try{
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
System.out.println(" successfully
connected\n");
}catch(Exception e){
System.out.println("erro message:"+e);
}
}
}
The setting for the oracle driver classpath use class
path variable with the below path c:\oracleexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar;.
THE BELOW PROGRAM IS AN EXAMPLE FOR THE JAVA SERVER PAGES
,JAVA DATABASE CONNECTIVITY AND TOMCAT SERVER
<%@page
import="java.sql.*"%>
<%@page
import="java.io.*"%>
<%
String
n=request.getParameter("name");
String p=request.getParameter("pass");
String
e=request.getParameter("email");
String
ph=request.getParameter("phone");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
System.out.println(" successfully connected\n");
String s="insert into
members
values('"+n+"','"+p+"','"+e+"','"+p+"')";
Statement
sm=con.createStatement();
sm.executeUpdate(s);
con.close();
%>
<body>
<form >
name:<input
type="text" name="name"><br>
password:<input
type="password" name="pass"><br>
email:<input
type="text" name="email"><br>
phone:<input
type="text" name="phone"><br>
<br><input
type="submit" value="register">
</form>
</body>
note:-
put this
code apache tomcat(d)->webapps(d)-ramu(d)-> ramu.jsp(note pad file ),and
web-inf(d) in this paste lib(d) with
ojdbc14.jar file inside of this lib folder
if you run
the above program by requesting url (take it.jsp ) for this program
first it will display one html page and ask u to fill the details after
pressing the submit button in this page rest of the jsp code will read data from the fields stores this into the oracle
specified table
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి