在oracle中建表可用sql语句或图形界面 *** 作。
一、sql语句:
1create table test
2(id int,
3name varchar2(10));
二、图形界面:
以PL/SQL为例:
1、登录到指定数据库。
2、左侧列表中找到Tables选项,并右键,选择新建。
3、在“一般”选项卡下,填写表名称,选择所属表空间。
4、在“列”选项卡下,填写字段名称及类型,然后点击“应用”按钮保存即可。
创建数据库了连接
编写数据库 *** 作语句
获取结果
import javasqlConnection;
import javasqlDriverManager;
import javasqlPreparedStatement;
import javasqlResultSet;
import javasqlSQLException;
import javasqlStatement;
import javautilList;
import javaxservletjspjstlsqlResult;
import javaxservletjspjstlsqlResultSupport;
public class BaseDao {
private static String driver = "oraclejdbcdriverOracleDriver";
private static String url = "jdbc:oracle:thin:@localhost:1521:orcl";
private static String user = "s2";
private static String pwd = "s2";
public static Connection getcon() {
Connection c = null;
try {
ClassforName(driver);
c = DriverManagergetConnection(url, user, pwd);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
eprintStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
return c;
}
public static int executeUpdate(String sql,Objectparam){
Connection c=getcon();
PreparedStatement p=null;
int num=0;
try {
p=cprepareStatement(sql);
if (param!=null) {
for (int i = 0; i < paramlength; i++) {
psetObject(i+1, param[i]);
}
}
num=pexecuteUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}finally{
try {
pclose();
cclose();
} catch (SQLException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
return num;
}
public static Result executeQuery(String sql,Objectparam){
Connection c=getcon();
PreparedStatement p=null;
ResultSet rs=null;
Result r=null;
try {
p=cprepareStatement(sql);
if (param!=null) {
for (int i = 0; i < paramlength; i++) {
psetObject(i+1, param[i]);
}
}
rs=pexecuteQuery();
r=ResultSupporttoResult(rs);
}catch (SQLException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}finally{
try {
rsclose();
pclose();
cclose();
} catch (SQLException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
return r;
}
}
微信公众平台是可以开发java调用oracle这类型的接口的,一般通过MyBatis连接Oracle数据库。
举例如下:
1、先建立一个数据库表,名为PERSON_INFO,建表SQL如下:
create TABLE PERSON_INFO
(
id number(12,0) PRIMARY KEY,
name varchar2(20) NOT NULL,
gender char(1) DEFAULT ' ',
remark varchar2(1000),
input_date number(10,0) DEFAULT to_number(to_char(sysdate,'yyyymmdd')),
input_time number(10,0) DEFAULT to_number(to_char(sysdate,'hh24miss'))
);
2、编写java程序,项目中文件的上下级关系如图:
3、构建mybatis配置映射关系
1)、导入JAR包:mybatis-322jar、ojdbc14-102020jar
2)、建立MyBatis配置文件mybatis-configxml
4、建立xml文件:PersonInfoMapperxml,其中实现了一个SQL语句:selectAllPersonInfo,查询所有的PERSON_INFO信息
5、建立对应的Java类:PersonInfo,其中各属性对应于数据表PERSON_INFO中的各字段
public class PersonInfo {
Long id;
String name;
String gender;
String remark;
Long inputDate;
Long inputTime;
public Long getId() {
return id;
}
public void setId(Long id) {
thisid = id;
}
public String getName() {
return name;
}
public void setName(String name) {
thisname = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
thisgender = gender;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
thisremark = remark;
}
public Long getInputDate() {
return inputDate;
}
public void setInputDate(Long inputDate) {
thisinputDate = inputDate;
}
public Long getInputTime() {
return inputTime;
}
public void setInputTime(Long inputTime) {
thisinputTime = inputTime;
}
}
6、建立对应的Java类:PersonInfoMapper
import javautilList;
public interface PersonInfoMapper {
List<PersonInfo> selectAllPersonInfo();
7、建立一个类MyBatisTest用于存放main函数,查询PERSON_INFO表中所有的数据并打印
import javaioInputStream;
import javautilList;
import orgapacheibatisioResources;
import orgapacheibatissessionSqlSession;
import orgapacheibatissessionSqlSessionFactory;
import orgapacheibatissessionSqlSessionFactoryBuilder;
/
MyBatis使用测试
@author pieryon
@date 2016年4月1日
@time 下午21:47:01
@remark
/
public class MyBatisTest {
public static void main(String[] args) {
try {
String resource = "mybatis-configxml";
InputStream inputStream = ResourcesgetResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()build(inputStream);
SqlSession session = sqlSessionFactoryopenSession();
try {
PersonInfoMapper mapper = sessiongetMapper(PersonInfoMapperclass);
List<PersonInfo> personInfos = mapperselectAllPersonInfo();
if (personInfos == null) {
Systemoutprintln("The result is null");
} else {
for (PersonInfo personInfo : personInfos) {
Systemoutprintln("---PersonInfo---");
Systemoutprintln("name:" + personInfoname);
Systemoutprintln("gender:" + personInfogender);
Systemoutprintln("remark:" + personInforemark);
Systemoutprintln("inputDate:" + personInfoinputDate);
Systemoutprintln("inputTime:" + personInfoinputTime);
Systemoutprintln();
}
}
} finally {
sessionclose();
}
} catch (Exception ex) {
exprintStackTrace();
}
}
}
8、运行main函数,控制台输出结果如下:
---PersonInfo---
name:Tsybius
gender:m
remark:-
inputDate:20160229
inputTime:225703
---PersonInfo---
name:Galatea
gender:f
remark:-
inputDate:20160228
inputTime:123456
给你一个能看懂的。
记得给兄我多加点分。谢谢了啊。
# 1、Oracle8/8i/9i数据库(thin模式)
# ClassforName("oraclejdbcdriverOracleDriver")newInstance();
# String url="jdbc:oracle:thin:@localhost:1521:orcl";
# //orcl为数据库的SID
# String user="test";
# String password="test";
# Connection conn= DriverManagergetConnection(url,user,password);
#
# 2、DB2数据库
# ClassforName("comibmdb2jdbcappDB2Driver ")newInstance();
# String url="jdbc:db2://localhost:5000/sample";
# //sample为你的数据库名
# String user="admin";
# String password="";
# Connection conn= DriverManagergetConnection(url,user,password);
#
# 3、Sql Server70/2000数据库
# ClassforName("commicrosoftjdbcsqlserverSQLServerDriver")newInstance();
# String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
# //mydb为数据库
# String user="sa";
# String password="";
# Connection conn= DriverManagergetConnection(url,user,password);
#
# 4、Sybase数据库
# ClassforName("comsybasejdbcSybDriver")newInstance();
# String url =" jdbc:sybase:Tds:localhost:5007/myDB";
# //myDB为你的数据库名
# Properties sysProps = SystemgetProperties();
# SysPropsput("user","userid");
# SysPropsput("password","user_password");
# Connection conn= DriverManagergetConnection(url, SysProps);
#
# 5、Informix数据库
# ClassforName("cominformixjdbcIfxDriver")newInstance(); String url =
# "jdbc:informix-sqli://123456789:1533/myDB:INFORMIXSERVER=myserver;
# user=testuser;password=testpassword";
# //myDB为数据库名
# Connection conn= DriverManagergetConnection(url);
#
# 6、MySQL数据库
# ClassforName("orggjtmmmysqlDriver")newInstance();
# String url ="jdbc:mysql://localhost/myDBuser=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
# //myDB为数据库名
# Connection conn= DriverManagergetConnection(url);
#
# 7、PostgreSQL数据库
# ClassforName("orgpostgresqlDriver")newInstance();
# String url ="jdbc:postgresql://localhost/myDB"
# //myDB为数据库名
# String user="myuser";
# String password="mypassword";
# Connection conn= DriverManagergetConnection(url,user,password);
8Oracle8/8i/9i数据库(thin模式)
//import javasql;
ClassforName("oraclejdbcdriverOracleDriver")newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
Connection conn= DriverManagergetConnection(url,%%2,%%3);
Statement stmtNew=conncreateStatement();
20数据库存入二进制字段数据
InputStream pic = new FileInputStream(dtoget(i)getLibPic());
sql = "INSERT INTO piclib (name,pic,sign,remark) VALUES (,,,)";
pstmt = conprepareStatement(sql);
pstmtsetString(1, dtoget(i)getName());
pstmtsetBinaryStream(2,pic,(int)dtoget(i)getLibPic()length());
21数据库取出二进制字段数据
//import javasql;
public class DemoDisplayBinaryDataFromDatabase {
public static Connection getConnection() throws Exception {
String driver = "oraclejdbcdriverOracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:databaseName";
String username = "name";
String password = "password";
ClassforName(driver);
Connection conn = DriverManagergetConnection(url, username, password);
return conn;
}
public static void main(String args[]) throws Exception {
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
String query = "SELECT raw_column, long_raw_column FROM binary_table WHERE id = ";
try {
conn = getConnection();
Object[] results = new Object[2];
pstmt = connprepareStatement(query);
pstmtsetString(1, "0001");
rs = pstmtexecuteQuery();
rsnext();
// materialize binary data onto client
results[0] = rsgetBytes("RAW_COLUMN");
results[1] = rsgetBytes("LONG_RAW_COLUMN");
} finally {
rsclose();
pstmtclose();
connclose();
}
}
}
以上就是关于怎么用java在oracle数据库中建表全部的内容,包括:怎么用java在oracle数据库中建表、如何使用java对oracle数据库进行增删查改、微信公众平台 java开发 能用oracle数据库吗等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)