连接数据库
来源:互联网 发布:哪里买古典音乐cd知乎 编辑:程序博客网 时间:2024/05/16 17:44
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Jdbc;
import Model.LoginInf;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
/**
* @author HP-Developerver
*/
public class Dao {
protected static String dbClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
protected static String dbUr1="jdbc:sqlserver://localhost:1433;DatabaseName=Student";
protected static String dbUser="sa";
protected static String dbPwd="1234";
protected static String second=null;
private static Connection conn=null;
private Dao(){
try {
if (conn==null) {
Class.forName(dbClassName);
conn= DriverManager.getConnection(dbUr1, dbUser,dbPwd);
}
else
return;
}
catch (Exception ee){
ee.printStackTrace();
}
}
static ResultSet executeQuery(String sql){
try{
if(conn==null)
new Dao();
return conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE).executeQuery(sql);
}catch(SQLException e){
e.printStackTrace();
return null;
}finally{
}
}
public static int executeUpdate(String sql){
try{
System.out.println(sql);
if(conn==null)
new Dao();
return conn.createStatement().executeUpdate(sql);
}catch (SQLException e){
System.out.println(e.getMessage());
return -1;
}
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Jdbc;
import Model.LoginInf;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
/**
* @author HP-Developerver
*/
public class Dao {
protected static String dbClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
protected static String dbUr1="jdbc:sqlserver://localhost:1433;DatabaseName=Student";
protected static String dbUser="sa";
protected static String dbPwd="1234";
protected static String second=null;
private static Connection conn=null;
private Dao(){
try {
if (conn==null) {
Class.forName(dbClassName);
conn= DriverManager.getConnection(dbUr1, dbUser,dbPwd);
}
else
return;
}
catch (Exception ee){
ee.printStackTrace();
}
}
static ResultSet executeQuery(String sql){
try{
if(conn==null)
new Dao();
return conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE).executeQuery(sql);
}catch(SQLException e){
e.printStackTrace();
return null;
}finally{
}
}
public static int executeUpdate(String sql){
try{
System.out.println(sql);
if(conn==null)
new Dao();
return conn.createStatement().executeUpdate(sql);
}catch (SQLException e){
System.out.println(e.getMessage());
return -1;
}
}
}
0 0
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 连接数据库
- 定制带第三方库的python,解决spark/hadoop环境中sklearn的调用问题
- IP网际协议,转载自实验楼
- 黄半仙算命系统5
- iOS 自定义cell(思路,以及详细步骤)
- RadioButton与ChecxBox
- 连接数据库
- 【转】jdbc事务处理
- 备忘录模式
- 构造函数与析构函数的顺序及动态内存的申请
- test8.17
- 使用 native2ascii.exe 将java utf-8编码批量转换为 ANSI.
- 实现秒杀的几个想法(续)
- C++基类,派生类,同名覆盖原则
- shell 之进行数学运算 let expr bc 中括号