-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
47 lines (35 loc) · 1.49 KB
/
Copy pathMain.java
File metadata and controls
47 lines (35 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package TEST;
import java.sql.*;
public class Main {
public static void main(String[] args) {
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";//SQL数据库引擎
String dbURL="jdbc:sqlserver://127.0.0.1;DatabaseName=test";//数据源 !!!!注意若出现加载或者连接数据库失败一般是这里出现问题
String Name="sa";
String Pwd="123456789";
Statement sql;
ResultSet rs;
try
{
Class.forName(driverName);
Connection conn=DriverManager.getConnection(dbURL,Name,Pwd);
System.out.println("连接数据库成功");
sql=conn.createStatement();
rs=sql.executeQuery("select * from 电影 order by '文件大小' ");
while (rs.next()){
System.out.print(rs.getString(1)+"\n");
System.out.print(rs.getString(2)+"\n");
System.out.print(rs.getString(3)+"\n");
//System.out.print(rs.getString(4)+"\t");
//System.out.print(rs.getString(2)+" ");
//System.out.print(rs.getString(3)+" ");
//System.out.print(rs.getString(4)+" ");
//System.out.print(rs.getString(5)+" ");
//System.out.print(rs.getString(6)+" ");
System.out.println();
}
}catch(Exception e){
e.printStackTrace();
System.out.println("连接失败");
}
}
}