连接SQL的话用java自带的jdbc驱动就可以
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn=DriverManager.getConnection("jdbc:odbc://202.101.224.68:3306/staff");
PreparedStatement pstmt1=conn.prepareStatement("SELECT * FROM Teacher");
ResultSet rs1=pstmt1.executeQuery();
...
conn.close();
pstmt.close();
rs.close();
}
catch(SQLException sqle) {
System.out.println(sqle.getMessage());
System.out.println(sqle.getSQLState());
}
这段代码就是用JdbcOdbc连接IP地址为202.101.224.68的staff数据库,查找其下的Teacher表
Db Name: Microsoft SQL Server 2000
JDBC Name: SQL Server 2000 Driver for JDBC
Home Page: http://www.microsoft.com/china/sql/
JDBC Ver: (SQL Server 2000 Driver for JDBC)
Download: http://www.microsoft.com/china/sql/downloads/2000/jdbc.asp
Conn Code:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection ("jdbc:microsoft:sqlserver://server1:1433","user","password");
代码和连接本地数据库没啥区别啊。
只是需要远程数据库开放远程访问的权限。
用jdbc指定运程的ip地址,再把你要用的端口号从防火墙中打开