当前位置:网站首页>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();
}
}
然后就连接成功
边栏推荐
- Eulato
- Typescript compilation options and configuration files
- How to understand CPU load
- log4j-slf4j-impl cannot be present with log4j-to-slf4j
- Elk - elastalert largest pit
- 2022 | framework for Android interview -- Analysis of the core principles of binder, handler, WMS and AMS!
- WordPress site link modification plug-in: Velvet Blues update URLs
- 快速搭建ELK7.3
- Collection of practical WordPress plug-ins (under update)
- The no category parents plug-in helps you remove the category prefix from the category link
猜你喜欢

Template engine - thymeleaf
![[JUC supplementary] immutable object, shared meta mode, final principle](/img/c1/c29229108a3f66b83d13b4d90d49f7.jpg)
[JUC supplementary] immutable object, shared meta mode, final principle

Qt中radioButton使用

Jest unit test description config json

Intermediate web development engineer, interview questions + Notes + project practice

Hang up the interviewer

JS addition and multiplication error resolution number precision

MSF CS OpenSSL traffic encryption

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

让你搞懂冒泡排序(C语言)
随机推荐
Learn 02 - slice, morphological change and dimension exchange of numpy multidimensional array
在毕设中学习03
The role of Gerber file in PCB manufacturing
JVM-类加载过程
C# 设置或验证 PDF中的文本域格式
C# 读取txt文件生成Word文档
17.4 creating multiple threads, data sharing problem analysis and case code
[file upload vulnerability 05] server suffix detection and bypass experiment (based on upload-labs-3 shooting range)
[第二章 基因和染色体的关系]生物知识概括–高一生物
01_ Description object_ Class diagram
快速搭建ELK7.3
Fast build elk7.3
大数相加(C语言)
Collection of practical WordPress plug-ins (under update)
程序员常用的命令符
JEST 单元测试说明 config.json
PS does not display text cursor, text box, and does not highlight after selection
What is the latest popular annuity insurance product with higher income in 202?
centos安装mysql5.7
[Chapter II Relationship between genes and chromosomes] summary of biological knowledge - Biology in grade one of senior high school