|
import java.sql.*;
public class MSSQLText
{
public static void main(String args[]) throws SQLException
{
String str="select * from USER_FILES";
Connection con = null;
//PreparedStatement pre = null;
ResultSet rs = null;
try {
System.out.println("开始建立连接");
con = getConnectionL();
System.out.println("已经建立连接");
// pre = con.prepareStatement(str,
// ResultSet.TYPE_SCROLL_INSENSITIVE,
// ResultSet.CONCUR_UPDATABLE);
// System.out.println("执行!");
rs=((Statement) con).executeQuery(str);
while(rs.next())
{
System.out.println(rs.getString("Name")+" ");
}
rs.close();
con.close();
}
catch(Exception err){
err.printStackTrace(System.out);
}
}
public static Connection getConnectionL() {
String strDriver = "com.sybase.jdbc.SybDriver";
Connection conn = null;
String url = "jdbc:sybase:Tds:localhost:4100/DBNAME?charset=eucgb";
try {
Class.forName(strDriver).newInstance();
} catch (Exception e) {
System.out.println(e.getMessage() + "driver");
}
try {
conn = DriverManager.getConnection(url, "sa", "111111");
} catch (Exception e) {
System.out.println(e.getMessage() + "driver");
}
return conn;
}
} |
|