当前位置:网站首页>Android 11+ 配置SqlServer2014+
Android 11+ 配置SqlServer2014+
2022-06-11 12:00:00 【Adorable_Rocy】
SqlServer有很多坑会踩,特别是在安卓环境下,踩的坑就更多了
1.下载jtds-1.3.1.jar包
这个包重要的地方在于连接Sqlserver承担了巨大的作用
2.配置数据库
public class DBUtils {
private static String IP = "192.168.8.52"; //IP地址 127.0.0.1以及10.0.0.2 没用的话建议换成局域网的地址
private static String DBName = "xxx"; //数据库名称
private static String USER = "sa"; //数据库用户名
private static String PWD = "123456"; //数据库密码
/** 创建数据库对象 */
public static Connection getConn(){
Connection conn = null;
try {
//注意这串字符串的顺序,不同的数据库版本这行不同。
Class.forName("net.sourceforge.jtds.jdbc.Driver");
//conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=QQ","sa","sa");
//注:连接SQLServer 2008 没有microsoft,把这个去掉问题解决。
System.out.println("驱动加载成功");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println("驱动加载失败");
}
try {
conn = DriverManager.getConnection("jdbc:jtds:sqlserver://"+IP+":1433/"+DBName+";charset=utf-8",USER,PWD);
System.out.println("数据库连接成功");
} catch (SQLException throwables) {
throwables.printStackTrace();
System.out.println("数据库连接失败");
}
return conn;
}
/** 查询数据库 */
public static String Query() {
String result = "";
try {
Connection conn = getConn();
String sql = "select * from lei";
Statement stmt = conn.createStatement();//
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
String s1 = rs.getString("id");
result += s1 + "\n";
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
result += "查询数据异常!" + e.getMessage();
}
return result;
}
public static void main(String[] args) {
DBUtils.getConn();
}
}
然后就连接成功
边栏推荐
- Pan domain SSL certificate, sectigo cheap wildcard certificate popularization plan
- 01_ Description object_ Class diagram
- Addition of large numbers (C language)
- Linux忘记MySQL密码后修改密码
- Fast build elk7.3
- arguments. Callee implement function recursive call
- arguments.callee 实现函数递归调用
- Node connects to MySQL database and writes fuzzy query interface
- Where is it safer to open an account for soda ash futures? How much does it cost to buy soda ash futures?
- Problems encountered in installing mysql8 under centos7.x couldn't open file /etc/pki/rpm-gpg/rpm-gpg-key-mysql-2022
猜你喜欢

Is the SSL certificate reliable in ensuring the information security of the website?

Notes on topic brushing (XIV) -- binary tree: sequence traversal and DFS, BFS

Apple mobileone: the mobile terminal only needs 1ms of high-performance backbone

PS does not display text cursor, text box, and does not highlight after selection

中级web开发工程师,面试题+笔记+项目实战

Solve the problem of swagger document interface 404

How to solve the problem that high-precision positioning technologies such as ultra wideband UWB, Bluetooth AOA and RTK cannot be widely used due to their high cost? Adopt the idea of integrated deplo

Interview experience of Xiaomi Android development post~

C# 设置或验证 PDF中的文本域格式

Maximum water container
随机推荐
What is the latest popular annuity insurance product with higher income in 202?
MYCAT sub database and sub table
【LeetCode】1049. Weight of the last stone II (wrong question 2)
[JUC supplementary] atomic class, unsafe
Take you to know about direct insertion sorting (C language)
arguments.callee 实现函数递归调用
微信web开发者,如何学习web开发
Elk - x-pack set user password
C reads TXT file to generate word document
Let WordPress support registered users to upload custom avatars
吊打面试官,涨姿势
Hamiltonian graph
Gestion de projets logiciels 7.1. Concept de base du calendrier du projet
Full Permutation (recursion, backtracking)
JEST 单元测试说明 config.json
iframe 传值
Elk - elastalert largest pit
InputStream读取文件OutputStream创建文件
Network protocol of yyds dry goods inventory: datagram socket for detailed explanation of socket protocol
Dominating set, independent set, covering set