首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

java与sql server2005 连接有关问题

2012-01-26 
java与sql server2005 连接问题package com.lzw.daoimport internalFrame.guanli.Itemimport java.sql.C

java与sql server2005 连接问题
package com.lzw.dao;
import internalFrame.guanli.Item;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import model.TbGysinfo;
import model.TbKhinfo;
import model.TbKucun;
import model.TbRkthDetail;
import model.TbRkthMain;
import model.TbRukuDetail;
import model.TbRukuMain;
import model.TbSellDetail;
import model.TbSellMain;
import model.TbSpinfo;
import model.TbUserlist;
import model.TbXsthDetail;
import model.TbXsthMain;
public class Dao {
protected static String dbClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
protected static String dbUrl = "jdbc:sqlserver://localhost:1433;"
+ "DatabaseName=db_JXC;SelectMethod=Cursor";
protected static String dbUser = "sa";
protected static String dbPwd = "13572173756";
protected static String second = null;
public static Connection conn = null;
static {
try {
if (conn == null) {
Class.forName(dbClassName).newInstance();
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
显示错误

com.microsoft.sqlserver.jdbc.SQLServerException: selectMethod Cursor 无效。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.lzw.dao.Dao.<clinit>(Dao.java:41)
at com.lzw.login.Login$2.actionPerformed(Login.java:54)

[解决办法]
protected static String dbClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
protected static String dbUrl = "jdbc:sqlserver://localhost:1433;"
+ "DatabaseName=db_JXC;SelectMethod=Cursor";
protected static String dbUser = "sa";
protected static String dbPwd = "13572173756";
protected static String second = null;
public static Connection conn = null;
static {
try {
if (conn == null) {
Class.forName(dbClassName).newInstance();
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
}

/////////////////////////////////////////////////////////////
protected static String dbUrl = "jdbc:sqlserver://localhost:1433;"
+ "DatabaseName=db_JXC;SelectMethod=Cursor";

这句话改为
protected static String dbUrl = “jdbc:sqlserver://localhost:1433;databasename=表名”;
这样就可以实现了

热点排行