如何在jsp中实现和mssql2000数据库的连接?例如在jsp页面上显示某一数据库中表的内容(步骤)

salmon 2002-05-11 11:09:02
如何在jsp中实现和mssql2000数据库的连接?例如在jsp页面上显示某一数据库中表的内容(步骤)
...全文
44 点赞 收藏 2
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dylanwolf 2002-05-11
String strDriver="org.gjt.mm.mysql.Driver";
String strConn="jdbc:mysql://localhost:3306/forum?user=dylanwolf&password=760726";
private Connection conn = null;
private Statement stmt = null;
ResultSet rs = null;

try {
Class.forName(strDriver).newInstance();
} catch (Exception E) {
System.err.println("²»ÄÜÁ¬½ÓMySqlÊý¾Ý¿â£¡");
}
}
ResultSet rs = null;
try {
conn = DriverManager.getConnection(strConn);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
}catch(SQLException ex) {
System.err.println("Ö´ÐÐSQLÓï¾ä³ö´í£º" + ex.getMessage());
}


while(rs.next())
{
out.println("<LI>rs.getString()</LI>")
...
}
回复
weidegong 2002-05-11
/**address: SQL Server的连接参数*/
String address = "jdbc:microsoft:sqlserver://192.168.7.6:1433";
/***user: 数据库用户名*/
String user="sa";
/**passwd: 用户密码*/
String passwd="";
/*数据库名*/
String database = "DMCADSQL";

DatabaseMetaData conMD = null;
java.sql.Statement stmt = null;
Connection con = null;
ResultSet sqlRst = null;


// try
// {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(address,user,passwd);

conMD = con.getMetaData();
con.setCatalog(database);
stmt = con.createStatement();
// }catch(Exception fs) {
// out.print("Connection ERROR</p> <br>");
// }
// out.print("Connection</p> <br>");

try
{
stmt=con.createStatement();
sqlRst = stmt.executeQuery("select drawing_code,version,file_name from drawing");
out.print("stmt OK");
}catch(Exception gr)
{
out.print("stmt ERROR");
}
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告