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)
我给环境变量,会影响数据库连接吗