⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javalinksqlserver.java

📁 本程序主要用于JAVA连接 MICROSOFT SQL200 ,献上此代码,供大家参考
💻 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 + -