Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to connect sqlserver2005 by calling java program in oracle

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This issue of the content of which Xiaobian will bring you about oracle in how to call java program even sqlserver2005, the article is rich in content and professional point of view for everyone analysis and description, read this article I hope you can have some harvest.

1. Log in under sys-sysdba of oracle

Write a java source program link sqlserver2005:

create or replace and compile java source named test as

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

public class excutesql1

{

public static String entry(String str1,String str2) {

String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

//load jdbc driver

String a = "0";

String dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=wb"; //link database service and driver sample

String userName = "sa"; //username

String userPwd = "giap"; //Password

Connection dbConn;

try {

a = "1";

Class.forName(driverName);

dbConn = DriverManager.getConnection(dbURL, userName, userPwd);

String sql = "insert into ry_jbxx (RYBH,XM) values ('" + str1

+ "','" + str2 + "')";

PreparedStatement pstmt = dbConn.prepareStatement(sql);

pstmt.addBatch();

pstmt.executeBatch();

a = "2";

} catch (Exception e) {

e.printStackTrace();

a = "error";

}

return a;

}

}

(Note: Java programs can be loaded into oracle by loadjava, or you can write java source by plsql)

2. Log in under sys-sysdba of oracle

Load sqlserver2005 driver to oracle with loadjava, execute under dos:

loadjava -u sys/giap@zhxtdb -r -v sqljdbc.jar

Test link success:

Write a function:

create or replace function insert2(a varchar2, b varchar2) return varchar2 as

language java name 'excutesql1.entry(java.lang.String,java.lang.String) return java.long.String';

Test links!~

(Note: Be sure to execute under sysdba)

Sqlserver2005 test database:

CREATE TABLE [dbo]. [msg](

[tel] [varchar](50) NOT NULL,

[msg] [varchar](50) NULL

)

3. After the test is successful, a table is built under the ordinary user (giapzhxt):

create table MSG

(

TEL VARCHAR2(20),

MSG VARCHAR2(200)

)

tablespace GIAPDATA

pctfree 10

initrans 1

maxtrans 255

storage

(

initial 64K

minextents 1

maxextents unlimited

);

4. Log in under sys-sysdba of oracle

New A Stored Procedure

create or replace procedure insertsqlserver2005(a varchar2, b varchar2) as

language java name 'excutesql1.entry(java.lang.String,java.lang.String)';

Log in to newA regular user (giapzhxt) under sys-sysdba to execute stored procedures using the triggers in the following table:

create or replace trigger tri_zhxt_msg

after insert on giapzhxt.msg

for each row

begin

insertsqlserver2005(:new.tel,:new.msg);

end tri_zhxt_msg;

The above is how to connect sqlserver2005 by calling java program in oracle shared by everyone. If there are similar doubts, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report