JSP connects Oracle applets (create data sheets, insert, display)

xiaoxiao2021-03-06  85

<% @ Page Import = "java.sql. *"%>

<% @ Page Import = "java.io. *"%>

<% @ Page Import = "java.util. *"%>

<%

Java.sql.connection lconn = NULL;

Java.sql.Statement Lstat = NULL;

Java.sql.resultset lrs = null;

Try

{

DriverManager.RegisterDriver (new oracle.jdbc.driver.OracleDriver ());

String Lurl = "Java: Oracle: Thin: @ 192.168.0.28: 1521: junzi";

// java: Oracle: Thin: means that this is this driver

@ SRV: 1521: Represents the name and port number of the server used

// DBNAME: Indicates the SID of the database

LCONN = DriverManager.getConnection (LURL, "GU", "jian");

LSTAT = lconn.createstatement ();

// Create a table

String CreateTableCoffees = "CREATE TABLE COFFEES"

(COF_NAME VARCHAR (32), SUP_ID INTEGER, Price Float, "

"Sales Integer, Total Integer";

Lstat.executeUpdate (CreateTableCoffees);

// Insert data

LSTAT.EXECUTEUPDATE ("INSERT INTO COFFEES VALUES ('Colombian', 101, 7.99, 0, 0)");

LSTAT.EXECUTEUPDATE ("INSERT INTO COFFEES VALUES ('Espresso', 150, 9.99, 0, 0)");

LSTAT.EXECUTEUPDATE ("INSERT INTO COFFEES VALUES ('Colombian_Decaf', 101, 8.99, 0, 0)");

LSTAT.EXECUTEUPDATE ("INSERT INTO COFFEES VALUES ('French_roast_Decaf', 49, 9.99, 0, 0)")

//search result

Lrs = LSTAT.ExecuteQuery ("Select * from coffeees");

//Show results

Out.println ("

");

While (lrs.next ()) {

Out.print ("

" lrs.getstring (1));

// Cof_name

Out.print ("

" Lrs.Getint (2));

// sup_id

Out.print ("

" Lrs.Getfloat (3));

// price

Out.print ("

" Lrs.Getint (4)); // Sales

Out.println ("

" Lrs.Getint (5));

// Total

}

Out.println ("");

Lrs.close ();

Lstat.close ();

} Catch (sqlexception e) {

Throw new servletexception (e);

} Finally {

Try {

IF (LCONN! = NULL)

LCONN.CLOSE ();

} Catch (sqlexception e) {

}

}

%>

转载请注明原文地址:https://www.9cbs.com/read-107028.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.044, SQL: 9