java code:
package com.sql2008.text;
import java.sql.*;
public class TestSql {
public static String dbDriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
public static String url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=mydba";
public static String us="admin";
public static String pw="master";
static PreparedStatement pst=null;
static Connection conn=null;
public void insertAll(){
String sql=
"insert into ebook(booktitle,author,price) values('null','null','null')";
try {
Class.forName(dbDriver);
conn=DriverManager.getConnection(url,us,pw);
pst=conn.prepareStatement(sql);
pst.executeBatch();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
TestSql tt=new TestSql();
tt.insertAll();
}
}
抛出异常:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sql2008.text.TestSql.insertAll(TestSql.java:17)
at com.sql2008.text.TestSql.main(TestSql.java:33)