package leaveword;
import java.sql.*;
public class DSbean
{
private String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private String url = "jdbc:microsoft:sqlserver://127.0.0.1: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;
}
}
package leaveword;
import java.sql.*;
public class test
{
public test()
{
}
Connection con = new DSbean().getConn();
try //这里报错:Connection con = new DSbean().getConn();
{
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from user_temp");
}
catch(Exception ex)
{
}
public static void main(String[] args)
{
test test = new test();
} //这里报错:<identifier> expected at line 22 (22:6)
}