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分钟无限期地运行插入程序。