import java.sql.*;
import java.io.*;
public class L_j {
public static void main(String[] args)throws IOException
{ test();}
public static String test(){
try
{
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String con="jdbc:microsoft:sqlserver://172.127.10.55:1433;DatabaseName=test";
String user="sa";
String password="";
Class.forName(driver);
System.out.println("驱动sqlserver成功");
Connection conn = DriverManager.getConnection(con,user,password);
System.out.println("连接sqlserver数据库成功");
Statement stmt=conn.createStatement();
String sql="select * from Student";
oraclejdbc();//得到oracle数据表的一个语句块
ResultSet ors=ostmt.executeQuery("select * from xxh_test");//ostmt cannot be resolved
while(ors.next()){
stmt.executeUpdate("insert into Student values('ors.getString(1)','ors.getString(2)','ors.getString(3)','ors.getString(4)'");
}
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData rsmd=rs.getMetaData();
int colcount=rsmd.getColumnCount();
while(rs.next())
{
for(int i=0;i<colcount;i++){
System.out.print(rs.getString(i+1)+"\t");
}System.out.println();
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception ex)
{
System.err.println(ex.getMessage());
}
return null;
} /**create a method
*get oracle for jdbc
*connection
*insert . update. delete*/
public static Statement oraclejdbc(){
Statement ostmt = null;
try
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("找到oracle驱动!");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print(e.getMessage());
}
String url="jdbc:oracle:thin:@web:1521:oradb";
Connection oconn=DriverManager.getConnection(url,"compiere","");
System.out.println("oracle驱动连接成功!");
ostmt=oconn.createStatement();
return ostmt;
}
catch(SQLException ex)
{
while(ex!=null)
{
System.out.println(ex.getSQLState());
}
}return null;
}
}
朋友们我现在想在两个不同的数据库里(SQLSERVER ,ORACLE)从一个数据表取出一些记录添加到另一个数据库的数据表里,实现这两个数据表里同步.看看我这段代码该怎么改才能实现我想要的结果.现在程序出错.就是那个ostmt朋友们帮忙解决下将会非常感谢!
import java.io.*;
public class L_j {
public static void main(String[] args)throws IOException
{ test();}
public static String test(){
try
{
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String con="jdbc:microsoft:sqlserver://172.127.10.55:1433;DatabaseName=test";
String user="sa";
String password="";
Class.forName(driver);
System.out.println("驱动sqlserver成功");
Connection conn = DriverManager.getConnection(con,user,password);
System.out.println("连接sqlserver数据库成功");
Statement stmt=conn.createStatement();
String sql="select * from Student";
oraclejdbc();//得到oracle数据表的一个语句块
ResultSet ors=ostmt.executeQuery("select * from xxh_test");//ostmt cannot be resolved
while(ors.next()){
stmt.executeUpdate("insert into Student values('ors.getString(1)','ors.getString(2)','ors.getString(3)','ors.getString(4)'");
}
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData rsmd=rs.getMetaData();
int colcount=rsmd.getColumnCount();
while(rs.next())
{
for(int i=0;i<colcount;i++){
System.out.print(rs.getString(i+1)+"\t");
}System.out.println();
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception ex)
{
System.err.println(ex.getMessage());
}
return null;
} /**create a method
*get oracle for jdbc
*connection
*insert . update. delete*/
public static Statement oraclejdbc(){
Statement ostmt = null;
try
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("找到oracle驱动!");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print(e.getMessage());
}
String url="jdbc:oracle:thin:@web:1521:oradb";
Connection oconn=DriverManager.getConnection(url,"compiere","");
System.out.println("oracle驱动连接成功!");
ostmt=oconn.createStatement();
return ostmt;
}
catch(SQLException ex)
{
while(ex!=null)
{
System.out.println(ex.getSQLState());
}
}return null;
}
}
朋友们我现在想在两个不同的数据库里(SQLSERVER ,ORACLE)从一个数据表取出一些记录添加到另一个数据库的数据表里,实现这两个数据表里同步.看看我这段代码该怎么改才能实现我想要的结果.现在程序出错.就是那个ostmt朋友们帮忙解决下将会非常感谢!
解决方案 »
- web
- 如何load一个image到另一个image里面?
- 求教学视频
- 本地机器写代码执行是没有问题 换台开发人员机器 发现有错误
- [Swing]如何设置文本框默认得到焦点
- 没道理不显示按钮的.那个小地方出错了..........
- Applet的一个难题,请大家帮助解决,谢谢!
- Method是String类型,值是一个函数的方法名,如何实现这个方法的调用?
- 关于JAVA和C/C++通过socket发送和接受数据的问题
- 对数据方面一窍不通,对于java来说应该学数据库的那些东西,SQL语句,或着一种开发工具MSSQLserver,Oracle,MySql大家能不能给我点建议,推荐
- 为何我用IE装载这个JApplet无法成功?(100分的送分题)
- 关于java代码的层次书写规范,高手指点一下,比较一下下面两种规范的优缺点
因为你在上面的ostmt没有定义,直接引用肯定就错了!!!!