import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
/**这个类是insert语句的用法
*/
class Jdbctest3
{
protected Jdbctest3()
{
}
public static void main(String[] args)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
/**Class.forName(xxx.xx.xx) 返回的是一个类, .newInstance()
后才创建一个对象 Class.forName(xxx.xx.xx);的作用是要求JVM查找并加载指定的类,
也就是说JVM会执行该类的静态代码段*/
}catch(ClassNotFoundException ce){
System.out.println(ce);
}
try{
String url="jdbc:odbc:test";
String str="INSERT INTO"
+"friends(name,address,salary)"
+"VALUES('朱八'+'深圳',25690)";
Connection con=DriverManager.getConnection(url);
Statement s=con.createStatement();
int rowcount = s.executeUpate(str);
String str1 = "select name,sum(salary)"
+from friends+group by name;
ResultSet rs = s.executeQuery(str1);
while (rs.next()) {
System.out.print(rs.getString(1)+ ""t");
System.out.print(rs.getInt(2)+ ""t");
System.out.println("");
}
rs.close();
s.close();
con.close();
} catch (SQLException ce) {
System.out.println(ce);
}
}
}
1 error
D:"code>javac Jdbctest3.java
Jdbctest3.java:32: ';' expected
+from friends+group by name?
^
1 error
会报这个错误
1.读万卷书
2.行千里路
3.阅人无数