易截截图软件、单文件、免安装、纯绿色、仅160KB

Java连接SQL Server数据库

用Java连接SQL Server2000数据库有多种方法,下面介绍其中最常用的两种(通过JDBC驱动连接数据库)。
1. 通过Microsoft的JDBC驱动连接。此JDBC驱动共有三个文件,分别是mssqlserver.jar、msutil.jar和msbase.jar,可以到微软的网站去下载(http://www.microsoft.com/downloads/details.aspx?FamilyId=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en),如果你下载的是setup.exe,还需要安装它,安装后会生成上面的三个jar文件。此JDBC驱动实现了 JDBC 2.0。
驱动程序名称:com.microsoft.jdbc.sqlserver.SQLServerDriver(即下面的classforname)
数据库连接URL:jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=dbname(即下面的url)
2. 通过JTDS JDBC Driver连接SQL Server数据库,此驱动的文件名为jtds-1.2.jar,下载路径为(http://sourceforge.net/project/showfiles.php?group_id=33291),此驱动支持Microsoft SQL Server (6.5, 7.0, 2000 和2005) 和Sybase,并且实现了JDBC3.0,是免费的。
驱动程序名称:net.sourceforge.jtds.jdbc.Driver(即下面的classforname)
数据库连接URL:jdbc:jtds:sqlserver://localhost:1433/dbname(即下面的url)
JDBC连接SQL Server数据库的Bean代码网上大把的有,下面摘录其中的一部分:(请将localhost和1433改成你实际应用中的SQL Server服务器地址和端口号,dbname改成你实际的数据库名)
import java.sql.*;
public class DatabaseConn {
private Connection conn;
private Statement stmt;
private String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=dbname";
private String classforname = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private String uid = "sa";
private String pwd = "password";
public DatabaseConn(){}
/**
* <p>通过Microsoft JDBC驱动获得数据库连接</p>
* @return Connection
* @exception ClassNotFoundException, SQLException
*/
public Connection getConnection()
{
try
{
Class.forName(classforname);
if (conn == null || conn.isClosed())
conn = DriverManager.getConnection( url, uid, pwd);
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
catch (SQLException ex)
{
ex.printStack


相关文档:

DB2 SQL PL介绍


DB2 SQL PL
SQL PL是DB2所支持的过程化语言,它是SQL/PSM标准的一个子集。其根据应用范围不同,又分为Inline SQL PL,Embeded SQL PL和Compiled SQL PL。
Inline SQL PL
适用范围:触发器、函数和方法,支持部分SQL PL,使用时要注意一些限制
语法规则:BEGIN ATOMIC ... END
Embeded SQL PL
适用范围:嵌入式,配� ......

SQL 2005溢用之:分拆列值

问题描述:
有表tb, 如下:
id          values
----------- -----------
1           aa,bb
2           aaa,bbb,ccc
欲按,分拆values列, 分拆后结果如下:
id& ......

SQL Server 2000 Java开发中当前日期的处理

1、在数据库建表的时候字段直接设置为DATETIME类型;
2、执行插入的时候使用如下语句:
PreparedStatement pstmt = conn.prepareStatement("insert into guestbook(gst_user,gst_title,gst_content,gst_ip,gst_time) values(?,?,?,?,getdate())");
3、要把日期从数据库中取出,执行如下语句:
     ......

sql语句

select *from student
select student_id from student
select student_id ,student_name from student
select student_id student_name from student  将student_name 作为student_id的别名处理
如:   select student_id a from student
 select a=student_id from student
从student表中分别� ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号