9 个解决方案
#1
怎么没人啊
#2
放在WEB-INF/lib文件夹下就可以 了
#3
直接复制放到webapp\WEB-INF\lib下面吧
#4
用myeclipse的话可以直接导入到你的工程 也就是加入lib里面
也可以在你需要导入的工程中 porperties->java build path->lirbraries中添加你jar文件的位置
也可以在你需要导入的工程中 porperties->java build path->lirbraries中添加你jar文件的位置
#5
那位高手 帮我看一下 这又是哪里错了啊 代码如下 编写的时候没有红叉 可又编译不出来 解决了我加分
import java.sql.*;
public class NewsFirstTitleDB1 {
public static void main(String[]arge){
Connection connection = null;
Statement statement = null;
try{
String strsql = "insert into FirstLevelTitle values(1,'医疗','管理','2009')"; //sql插入语句
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException ex){
ex.printStackTrace();
System.out.println("无法找驱动类");
}
connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhose:1433;DatabaseName=news");
statement=connection.createStatement();
statement.executeUpdate(strsql);
}catch(SQLException de){
de.printStackTrace();
System.out.println("插入失败");
}finally{
closeStatement(statement); //调用方法关闭Statement连接
closeConnection(connection);//调用方法关闭数据库连接Connection
}
}
public static void closeStatement(Statement sjt){//关闭Statement连接
try{
if(sjt!=null){
sjt.close();
sjt=null;
}
}catch(SQLException et){
et.printStackTrace();
System.out.println("Statement关闭失败");
}
}
public static void closeConnection(Connection cin){ //关闭数据库连接Connection
try{
if(cin!=null&&(!cin.isClosed())){
cin.close();
}
}catch(SQLException de){
de.printStackTrace();
System.out.println("Connection关闭失败");
}
}
}
异常代码如下
Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
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 NewsFirstTitleDB1.main(NewsFirstTitleDB1.java:9)
import java.sql.*;
public class NewsFirstTitleDB1 {
public static void main(String[]arge){
Connection connection = null;
Statement statement = null;
try{
String strsql = "insert into FirstLevelTitle values(1,'医疗','管理','2009')"; //sql插入语句
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException ex){
ex.printStackTrace();
System.out.println("无法找驱动类");
}
connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhose:1433;DatabaseName=news");
statement=connection.createStatement();
statement.executeUpdate(strsql);
}catch(SQLException de){
de.printStackTrace();
System.out.println("插入失败");
}finally{
closeStatement(statement); //调用方法关闭Statement连接
closeConnection(connection);//调用方法关闭数据库连接Connection
}
}
public static void closeStatement(Statement sjt){//关闭Statement连接
try{
if(sjt!=null){
sjt.close();
sjt=null;
}
}catch(SQLException et){
et.printStackTrace();
System.out.println("Statement关闭失败");
}
}
public static void closeConnection(Connection cin){ //关闭数据库连接Connection
try{
if(cin!=null&&(!cin.isClosed())){
cin.close();
}
}catch(SQLException de){
de.printStackTrace();
System.out.println("Connection关闭失败");
}
}
}
异常代码如下
Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
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 NewsFirstTitleDB1.main(NewsFirstTitleDB1.java:9)
#6
没有找到数据库驱动
还是没有导入数据库驱动程序
还是没有导入数据库驱动程序
#7
我导入了mssqlserver.jar 放到工程的WEB-INF/lib目录下了 救命啊!!
#8
msutil.jar
msbase.jar
这两个呢?
msbase.jar
这两个呢?
#9
mssqlserver.jar msutil.jar msbase.jar这3个包 都要COPY到WEB/LIB目录下
#1
怎么没人啊
#2
放在WEB-INF/lib文件夹下就可以 了
#3
直接复制放到webapp\WEB-INF\lib下面吧
#4
用myeclipse的话可以直接导入到你的工程 也就是加入lib里面
也可以在你需要导入的工程中 porperties->java build path->lirbraries中添加你jar文件的位置
也可以在你需要导入的工程中 porperties->java build path->lirbraries中添加你jar文件的位置
#5
那位高手 帮我看一下 这又是哪里错了啊 代码如下 编写的时候没有红叉 可又编译不出来 解决了我加分
import java.sql.*;
public class NewsFirstTitleDB1 {
public static void main(String[]arge){
Connection connection = null;
Statement statement = null;
try{
String strsql = "insert into FirstLevelTitle values(1,'医疗','管理','2009')"; //sql插入语句
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException ex){
ex.printStackTrace();
System.out.println("无法找驱动类");
}
connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhose:1433;DatabaseName=news");
statement=connection.createStatement();
statement.executeUpdate(strsql);
}catch(SQLException de){
de.printStackTrace();
System.out.println("插入失败");
}finally{
closeStatement(statement); //调用方法关闭Statement连接
closeConnection(connection);//调用方法关闭数据库连接Connection
}
}
public static void closeStatement(Statement sjt){//关闭Statement连接
try{
if(sjt!=null){
sjt.close();
sjt=null;
}
}catch(SQLException et){
et.printStackTrace();
System.out.println("Statement关闭失败");
}
}
public static void closeConnection(Connection cin){ //关闭数据库连接Connection
try{
if(cin!=null&&(!cin.isClosed())){
cin.close();
}
}catch(SQLException de){
de.printStackTrace();
System.out.println("Connection关闭失败");
}
}
}
异常代码如下
Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
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 NewsFirstTitleDB1.main(NewsFirstTitleDB1.java:9)
import java.sql.*;
public class NewsFirstTitleDB1 {
public static void main(String[]arge){
Connection connection = null;
Statement statement = null;
try{
String strsql = "insert into FirstLevelTitle values(1,'医疗','管理','2009')"; //sql插入语句
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException ex){
ex.printStackTrace();
System.out.println("无法找驱动类");
}
connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhose:1433;DatabaseName=news");
statement=connection.createStatement();
statement.executeUpdate(strsql);
}catch(SQLException de){
de.printStackTrace();
System.out.println("插入失败");
}finally{
closeStatement(statement); //调用方法关闭Statement连接
closeConnection(connection);//调用方法关闭数据库连接Connection
}
}
public static void closeStatement(Statement sjt){//关闭Statement连接
try{
if(sjt!=null){
sjt.close();
sjt=null;
}
}catch(SQLException et){
et.printStackTrace();
System.out.println("Statement关闭失败");
}
}
public static void closeConnection(Connection cin){ //关闭数据库连接Connection
try{
if(cin!=null&&(!cin.isClosed())){
cin.close();
}
}catch(SQLException de){
de.printStackTrace();
System.out.println("Connection关闭失败");
}
}
}
异常代码如下
Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/jdbc/base/BaseDriver
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 NewsFirstTitleDB1.main(NewsFirstTitleDB1.java:9)
#6
没有找到数据库驱动
还是没有导入数据库驱动程序
还是没有导入数据库驱动程序
#7
我导入了mssqlserver.jar 放到工程的WEB-INF/lib目录下了 救命啊!!
#8
msutil.jar
msbase.jar
这两个呢?
msbase.jar
这两个呢?
#9
mssqlserver.jar msutil.jar msbase.jar这3个包 都要COPY到WEB/LIB目录下