package leaveword;
import java.sql.*;
import java.text.*;
import java.util.Date;
public class DSbean
{
private String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private String url = "jdbc:micosoft:sqlserver://localhost:1433;DatabaseName = leaveword";
private String user = "sa";
private String password = "sa";
Connection conn = null;
public DSbean()
{
}
public Connection getConn()
{
try
{
System.out.println("one");
Class.forName(driver);
conn = DriverManager.getConnection(url,user,password);
System.out.println("two");
}
catch(Exception ex)
{
ex.printStackTrace();
}
return conn;
}
public String chineseEx(String str)
{
if(str == null)
{
str = "";
}
else
{
try
{
str = new String(str.getBytes("iso-8859-1"),"gb2312");
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
return str;
}
public String getDate()
{
String datestr = "";
SimpleDateFormat df = new SimpleDateFormat("yyyy年mm月dd日");
Date dt = new Date();
datestr = df.format(dt);
return datestr;
}
public static void main(String[] args)
{
DSbean dsbean = new DSbean();
dsbean.getConn();
System.out.println("three");
}
}
错误:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at leaveword.DSbean.getConn(DSbean.java:24)
at leaveword.DSbean.main(DSbean.java:64)
我给环境变量,会影响数据库连接吗
----------------解决方案--------------------------------------------------------
驱动啊驱动~
----------------解决方案--------------------------------------------------------
我导入了呀!昨天我都用的好好的,今天改了一下环境变量就不行了java.sql.SQLException: No suitable driver
----------------解决方案--------------------------------------------------------
你改的是哪个环境变量呀?
----------------解决方案--------------------------------------------------------
没有驱动啊!还是不要配了,每次做的时候把他加进去吧!不然环境变量一改出了错都不知道是怎么回事!
----------------解决方案--------------------------------------------------------
为啥不用数据库连接池?方便,迅速,代码通用性好
----------------解决方案--------------------------------------------------------
对,做网站就需要连接池技术的
----------------解决方案--------------------------------------------------------