📄 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 + -