import java.sql.*;
public class jdbc {
public static void main(String[] args)
{
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("Driver loaded");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("not loaded");
}
String connectionUrl = "jdbc:sqlserver://172.**.**.**:1433;" +"databaseName=dbname;user=user;password=pwd;";
Connection con=null;
Statement stmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionUrl);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("CONNECTED");
try {
stmt = con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
rs=stmt.executeQuery("select * FROM [dbname].[dbo].[VwZoneCount]");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
while(rs.next())
{
System.out.print(rs.getString("Zone Name")+"\t");
System.out.print(rs.getInt("Zone Count")+"\t");
System.out.println(rs.getString("Phase Name"));
;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
从这段代码中,我从远程 sql server 中提取数据。我需要将此数据插入到我的本地机器 sql server 中。我该怎么做?
我还需要每 15 分钟无限期地自动运行一次插入程序。