JAVA 连接ORACLE数据库代码
import java.net.url;
import java.sql.*;
public class javaoracle {
public javaoracle() {
}
public static void main(string[] args){
try
{
try{
class.forname("oracle.jdbc.driver.oracledriver");
}
catch(java.lang.classnotfoundexception e)
{
system.err.print(e.getmessage());
}
string url="jdbc:oracle:thin:@server:1521:sdcdb";
connection conn=drivermanager.getconnection(url,"test","test");
statement stmt=conn.createstatement();
resultset rs=stmt.executequery("select score from my");
while(rs.next())
{
system.out.println(rs.getstring(1));
}
conn.close();
}
catch(sqlexception ex)
{
while(ex!=null)
{system.out.println(ex.getsqlstate());
}
}
}
}
///////////////////////
在try{}中: Class.forName("oracle.jdbc.driver.OracleDriver");
//将OracleDriver载入JVM对象池
抛出:ClassNotFoundException
3.连接数据库: Connection con=DriverManager.getConnection("jdbc:oracle:thin:ordertemp/ordetemp@localhost:1521:GY");
数据库类型标识符: jdbc:odbc:thin
登陆用户名: ordertemp
登陆密码: ordertemp
数据库服务器IP地址:localhost (或者用127.0.0.1,如果是网络,则为URL)
数据虚拟端口号: 1521 (oracle默认端口号) //(sqlserver默认端口号1433)
数据库SID: GY
抛出:SQLException
4.创建Statement对象(PreparedStatement也可以)
Statement stm=con.createStatement();
PreparedStatement psm=con.prepareStatement(String sql);
5.执行相关SQL查询语句及获得结果。
6.结束之后,必须使用: stm.close();  
相关文档:
SQL:结构化查询语言
C R U D: 增删改查
table : name age score
desc+表名 ---> 查询表结构
或者用 describe 命令 (desc是describe的简写)
查询语言:SELECT [DISTINCT] {*,column[alias],...} from table;
SELECT identifies what columns from identifies which tab ......
外键约束保证参照完整性。外键约束限定了一个列的取值范围。一个例子就是限定州名缩写在一个有限值集合中,这个值集合是另外一个控制结构——一张父表
下面我们创建一张参照表,它提供了完整的州缩写列表,然后使用参照完整性确保学生们有正确的州缩写。第一张表是州参照表,State作为主键
......
Oracle 表删除大量数据后,即使表中只有几行记录,但用select count(*) from table 来查询发觉都不会马上出来,原因是该表的空间大了,查询起来很慢。解决的方法是把该表所占用的表空间缩小,或者说释放表空间。
alter table XXXX move; 这样处理后就释放了表空间了。但是释放表空间后,表的行号rowid会发生变化,而基于 ......
停止数据库,停止服务。
然后在运行升级程序时出现Error:OUI-10133:Invalid stageing area. there
are no top level components
错误,半天不得其解。终于发现是因为升级包解压不完全造成的。重新复制一份完整解压过的,升级。OK. ......
CREATE OR REPLACE FUNCTION OFFICE.fbill_getbalance (billid NUMBER, total NUMBER)
RETURN NUMBER
IS
paid NUMBER;
balance NUMBER;
BEGIN
balance := total;
--get total paid
SELECT SUM (n_paidamount)
&nb ......