?? javalinksqlserver.java
字號:
import java.sql.*;
public class JavaLinkSQLServer
{
public static void main(String[] args)
{ String DBdirver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String ConnStr = "jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=XX;User=sa;Password=sa";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName(DBdirver);
conn = DriverManager.getConnection(ConnStr);
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from Job_Info");
while(rs.next())
{
System.out.println(rs.getString("Job_Name"));
}catch(ClassNotFoundException ex )
{ex.printStackTrace();}
catch(SQLException e )
{
System.out.println("SQLException:"+e.getMessage());
System.out.println("SQLState:"+e.getSQLState());
System.out.println("VenderError:"+e.getErrorCode());
}finally{
try{
if(rs != null)
rs.close();
rs = null;
if(stmt != null)
stmt.close();
stmt = null;
if(conn != null)
conn.close();
conn = null;
}catch(SQLException e )
{
e.getMessage();
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -