Get the App
SLTechnology News&Howtos  ›  Database  › 

How to connect sqlserver2005 by calling java program in oracle

Shulou Source: shulou.com Published: 2022-05-31 19:34:11 10月15日 Update

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.

Tags: Program link test login user driver ordinary successful content data database process analysis storage professional small and medium rich in content function password that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Redmi Microsoft Linux Shulou Tech Info