eclipse java程序出错,请高手指教哈!
packagedatabase;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql...
package database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class database1 {
static Connection conn=null;
static Statement st=null;
ResultSet rs=null;
public static void main(String []args)
{
try {
//加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
//建立连接
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=ZC_NmSoft","chen","");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
//创建语句对象
st = conn.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String sql="cteate table user(\r\n"+" age bigint(8)default NULL,\r\n"+")";
try{
st.execute(sql);
st.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
出现错误如下:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
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.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at database.database1.main(database1.java:18)
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost:1433;DatabaseName=ZC_NmSoft
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at database.database1.main(database1.java:25)
Exception in thread "main" java.lang.NullPointerException
at database.database1.main(database1.java:32) 展开
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class database1 {
static Connection conn=null;
static Statement st=null;
ResultSet rs=null;
public static void main(String []args)
{
try {
//加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
//建立连接
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=ZC_NmSoft","chen","");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
//创建语句对象
st = conn.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String sql="cteate table user(\r\n"+" age bigint(8)default NULL,\r\n"+")";
try{
st.execute(sql);
st.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
出现错误如下:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
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.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at database.database1.main(database1.java:18)
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost:1433;DatabaseName=ZC_NmSoft
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at database.database1.main(database1.java:25)
Exception in thread "main" java.lang.NullPointerException
at database.database1.main(database1.java:32) 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询