myeclispe在本机上,而SqlServer2005在另一台电脑上,该怎么连,求具体步骤
解决方案 »
- javax.imageio.IIOException: Can't read input file!
- insert 的时候提示标识符太长,请问怎么解决
- 不显示删除回复显示所有回复显示星级回复显示得分回复 >>>急急急啊!大虾进啊!wap页面空格效果没显示
- 在模态(modal)窗口中用window.open打开窗口的问题。
- 关于正则表达的疑问
- 程序出错 跪求答案!在线等等
- 在哪里可以下载jspsmart组件
- 我想找一个能够上传文件的 servelet or javabean ? 谢谢诶!
- 如何用servlet,把一个Word文档输出到WEB客户端???在线等待!!!
- 为什么我的程序不能显示中文的!
- Jetty中如何运行SpringMVC
- 关于jsp页面验证和清除session的问题???
试图DB Brows出来了,选中它右键有个new的选项,在里面填好即可
把localhost换成对方的ip地址不就完了
[/Quote]
这个完全能够解决!lz是用hibernate链接sqlserver2005?这样也是一样的,要导入包
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;public class BaseDao {
public final static String DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public final static String URL="jdbc:sqlserver://localhost:1433;databaseName=数据库名";
public final static String DBNAME="用户名";
public final static String DBPASS="用户密码";
public Connection getConn() throws ClassNotFoundException,SQLException{
Class.forName(DRIVER);
Connection conn=DriverManager.getConnection(URL,DBNAME,DBPASS);
return conn;
}
public void closeAll(Connection conn,PreparedStatement pstmt,ResultSet rs){
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(pstmt!=null){
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public int executeSQL(String preparedSql,String[] param){
Connection conn=null;
PreparedStatement pstmt=null;
int num=0;
try {
conn=this.getConn();
pstmt=conn.prepareStatement(preparedSql);
if(pstmt!=null){
for(int i=0;i<param.length;i++){
pstmt.setString(i+1, param[i]);
}
}
num=pstmt.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally{
this.closeAll(conn, pstmt, null);
}
return num;
}
}
楼主有疑惑就问我!
还有更加简单的是
点击myeclipse 右上角 debug旁边的黄色小加号
选择Myeclpse Datebase Explorer
在里面自己写
但是连接jar包 自己一定要搞到 放到WEB-INF下的lib下
右键Database Connections选择new,Connection Profile Types选择SQL Server
里面配置。注意要有驱动程序jar包sqljdbc.jar