oracle外部java例程访问其它数据库的问题
为什么总是返回error 也就是捕获了异常,我把它改成application程序 运行起来都是正确的呀! 请各位大虾帮忙指点一下!程序如下:
create or replace and compile java source named erptowms as
import java.sql.*;
import java.util.*;
public class ErpToWms
{
public static String entry() throws Exception
{
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
PreparedStatement pstmt = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/libdb";
Properties sysProps = System.getProperties();
sysProps.put("user", "root");
sysProps.put("password", "888");
conn = DriverManager.getConnection(url, sysProps);
String strSql = "insert into login values('wei','hehe')";
pstmt = conn.prepareStatement(strSql);
pstmt.executeUpdate();
return "ok";
} catch (Exception e) {
e.printStackTrace();
return "error";
} finally {
try {
if (null != rs)
rs.close(); if (null != pstmt)
pstmt.close();
if (null != conn)
conn.close(); } catch (SQLException e) {
e.printStackTrace();
}
}
}
}
为什么总是返回error 也就是捕获了异常,我把它改成application程序 运行起来都是正确的呀! 请各位大虾帮忙指点一下!程序如下:
create or replace and compile java source named erptowms as
import java.sql.*;
import java.util.*;
public class ErpToWms
{
public static String entry() throws Exception
{
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
PreparedStatement pstmt = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/libdb";
Properties sysProps = System.getProperties();
sysProps.put("user", "root");
sysProps.put("password", "888");
conn = DriverManager.getConnection(url, sysProps);
String strSql = "insert into login values('wei','hehe')";
pstmt = conn.prepareStatement(strSql);
pstmt.executeUpdate();
return "ok";
} catch (Exception e) {
e.printStackTrace();
return "error";
} finally {
try {
if (null != rs)
rs.close(); if (null != pstmt)
pstmt.close();
if (null != conn)
conn.close(); } catch (SQLException e) {
e.printStackTrace();
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货