JSP中连接SQL 2000数据库的问题总结
由于系统需求,最近在开发过程中将系统从原来的MySQL转移到SQL
2000下,其中遇到了诸多问题,花费了我不少时间。现在把我的经验拿出来告诉大家,好让大家少走弯路,节约时间。
首先是SQL
2000数据库的安装问题,在此我主要讲些关于SQL 2000的版本与操作系统的兼容性问题:SQL
2000总共有7个不同版本,适应不同等级用户的需求。
我试了一下,在XP系统下只有“个人开发版”能正常安装而不出现错误,所以大家在安装时要注意,具体安装时的配置参照相关说明就可以了。
下面说明如何连接到SQL
2000数据库,首先当然是要下载JDBC驱动程序,最好去微软官方网站下载,然后将下载到的三个JAR包放入你的WEB应用的WEB-INF/lib/下。接下来编写程序进行测试:
/***********************************************
/*
/*DBTest.java
/*
/******************************************* */
import java.sql.*;
public class DBTest
{
Connection con;
Statement sta;
ResultSet rs;
String driver;
String url;
String user;
String pwd;
public DBTest()
{
driver = "com.microsoft.jdbc.
sqlserver.SQLServerDriver";;
url = "jdbc:microsoft:sqlserver:
//localhost:1433;DatabaseName =test";
//test为数据库名
user = "sa";
pwd = "sa";
//请更改为你相应的用户和密码
init();
}
public void init()
{
try{
Class.forName(driver);
System.out.println("driver is ok");
con = DriverManager.
getConnection(url,user,pwd);
System.out.println("conection is ok");
sta = con.createStatement();
rs = sta.executeQuery
("select * from room");
while(rs.next())
System.out.println
(rs.getInt("roomNum"));
}catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String args[])
//自己替换[]
{
new DBTest();
}
}
按道理讲,上边这段代码应该没错,可首先我们来看一下,如果sqlser服务器没有升级到sp3(在使用jdbc时,如果系统是xp或者
相关文档:
第一种:
public void deleteUser(String byemail) {
Session session = getSession();
Transaction transaction = null;
String hql = "delete from Register where email=?
";
try {
transaction = session.beginTransactio ......
/*当执行SQL时发现不能连接数据库,先重连一次*/
import java.io.FileInputStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
......
一.注释
-- 单行注释,从这到本行结束为注释sql 语法,类似C++,c#中//
/* … */ 多行注释,类似C++,C#中/* … */
二.变量(int, smallint, tinyint, decimal,float,real, money ,smallmoneysql 语法, text ,image, char, varchar。。。。。。)
语法:
DECLARE
&nb ......
-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comm ......