A java code
2024-08-24 13:54:52
With the help of LiJun I got a piece of JAVA code. With this code, I can do below things like connect to oracle database with jdbc driver and run sql.
Below are the Java code.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
*
* @author xx
*/ public class TestJDBC {
static Connection conn= null;
static String url="jdbc:oracle:thin:@pnd:1521:pnd";
static String username="pnadm";
static String password="password"; public TestJDBC()
{
try{
String driverclass="oracle.jdbc.driver.OracleDriver";
Class.forName(driverclass).newInstance();
conn=DriverManager.getConnection(url,username,password);
}catch(Exception e){
e.printStackTrace();
}
}
public static void getDate(){
String sql="select object_name from all_objects where rownum<2";
try{
Statement stmt=conn.createStatement();
ResultSet rs1=stmt.executeQuery(sql); while(rs1.next()){
System.out.print(rs1.getString("object_name")+" ");
}
}catch(Exception e){
e.printStackTrace();
} } public static void main(String[] args) {
TestJDBC t = new TestJDBC();
for (int i=0;i <30 ; i++)
t.getDate(); try {
Thread.sleep(30000);
} catch (InterruptedException e) {
} for (int i=0;i <280 ; i++)
t.getDate(); try {
Thread.sleep(300000);
} catch (InterruptedException e) {
} }
}
There is something important I need to record down.
1. You need to specify classpath environment variable for example
export CLASS_PATH=/opt/oracle/product/10.2/jdbc/lib/ojdbc14.jar
2. You can get the jdbc driver from oracle directory
最新文章
- 编译安装zabbix3.2
- 回头再看N层架构(图解)
- LVS+MYCAT读写分离+MYSQL同步部署手册(第三版)
- IIS7.5
- JavaScript深入浅出1-数据类型
- matlab批量合并txt文件
- java入门第二步之helloworld【转】
- postgresql cast转换类型
- cocos2dx使用tolua关于字符串处理的一个问题
- 查看TOMCAT内存使用情况 以及修改方法
- 一.redis 环境搭建
- JavaScript Boolean(布尔)对象
- JAVA设计模式--学习总结(序)
- iOS------自动查找项目中不用的图片资源
- Spring扫面路径配置不全导致异常 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 的原因
- import、export 和export default區別
- WebLogic Server Components:XA Transactions
- Java序列化的作用和反序列化
- C#打印0到100的素数
- 知识点【JavaScript模块化】
热门文章
- [Swift通天遁地]三、手势与图表-(8)制作股市中常用的蜡烛图表
- Java线程之Synchronized用法
- skiing 暴力搜索 + 动态规划
- 题解报告:hdu 1575 Tr A
- JSP所需要掌握的部分
- Linux命令(002) -- free
- C++ friend关键字
- Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named &#39;empid&#39; in &#39;class cn.happy.entity.Emp&#39;
- C++ Primer(第4版)-学习笔记-第2部分:容器和算法
- mysql中返回当前时间的函数或者常量