81,092
社区成员
发帖
与我相关
我的任务
分享
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databasename=student";
String user="sa";
String password="";
Connection con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
//下面这些单引号、双引号和加号起什么作用?
String sql="insert into score values('"+studentId+"','"+studentName+"','"+studentScore+"','"+studentClass+"')"; stmt.executeUpdate(sql);
stmt.close();
con.close();
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databasename=student";
String user="sa";
String password="";
Connection con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
//下面这些单引号、双引号和加号起什么作用?
String sql="insert into score values('"+studentId+"','"+studentName+"','"+studentScore+"','"+studentClass+"')";
System.out.println(sql); //新增的
stmt.executeUpdate(sql);
stmt.close();
con.close();
执行下 楼主自然会明白String sql="insert into score values('"
+studentId
+" ',' "
+studentName
+" ',' "
+studentScore
+" ',' "
+studentClass
+" ')";
不知道这样,你是否能看的更明白。