http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=136123
解决方案 »
- 解析编码为big5的网页源代码“恒”字读下来就乱码的问题?
- 在SSH2中提交多个对象页面中如何处理
- conn=ds.getConnection();为什么conn会为空呢?请大家帮忙!
- 如何用JSP获取HTML标签的值
- 有什么办法能把日期类型或者String的数据竖起来显示呢?关于JfreeChart搜索了csdn但是没有答案啊!(解决了给500分阿)
- 求jsp页面上decorator的用法??decorate的详细文档
- 我是初学者,请帮我解决这个有关javabean的问题
- 菜鸟,各位大虾指教!!!!
- JSP连结数据库,急!!
- 紧急:请问为什么必须用APACHE+TOMCAT才能浏览JSP文件
- 一个我实在是想不通的问题,请诸位高手指点
- 如何关掉游标、
http://www.csdn.net/develop/read_article.asp?id=18900
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url =" jdbc:sybase:Tds:localhost:5007/tsdata";
//tsdata为你的数据库名
Properties sysProps = System.getProperties();
SysProps.put("user","userid");
SysProps.put("password","user_password");
Connection conn= DriverManager.getConnection(url, SysProps);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
import java.sql.*;public class conn {
//String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
//String sConnStr = "jdbc:odbc:vote";
Connection connect = null;
ResultSet rs = null;
Statement stmt=null;
//====================================================================
String user="sa"; //连接数据库的用户名
String password="nrcrd"; //连接数据库的密码,
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=NJGH";
//上面一行为访问sql server2000的数据库地址和名字
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
//上面一行为访问sql server2000的数据库的驱动程序地址,建议把驱动放在tomcat的WEB-INF/classes下
//=====================================================================
public void init() {
rs=null;
try
{
Class.forName(driver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println( e.getMessage());
}
}
public ResultSet Open(String sql) {
rs = null;
try
{
connect =DriverManager.getConnection(url,user,password);
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return rs;
}
public int Excute(String sql) throws SQLException,java.io.UnsupportedEncodingException
{ int i=0;
int n=0;
try
{
connect =DriverManager.getConnection(url,user,password);
connect.setAutoCommit(false);
Statement stmt = connect.createStatement();
i=stmt.executeUpdate(sql);
connect.commit();
stmt.close();
connect.close();
}
catch(SQLException ex)
{ connect.rollback();
i=0;
}
return i ;
}
public void Close(){
try{
if (rs!=null) rs.close();
if (stmt!=null) stmt.close();
if (connect !=null) connect.close();}
catch(SQLException ex)
{}
}}
请交:这一句是什么意思?我是菜鸟,实在看不懂!望高手指点迷津!!!
现在一本jsp或者j2ee或者serlert的书下载它的源程序上面的例子很不错的