本文介绍了java.lang.ClassNotFoundException Netbeans java derby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Netbeans,做一个java应用程序。我在netbeans中使用Java DB创建了一个类ConnectDB for db connetion。我启动了服务器和十个连接到db。当我运行它生成的文件
java.lang.ClassNotFoundException:org.apache.derby.jdbc.ClientDriver @ 25 line
和
java.sql.SQLException:没有找到适合的驱动程序jdbc:derby:// localhost:1527 / Libraryprj; create = true
@第30行代码
代码如下
package Lms;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
/ **
*
* @author JOJO
* /
public class ConnectDB {
static Connection conn;
public static void main(String [] args){
String driver =org.apache.derby.jdbc.ClientDriver;
String connectionURL =jdbc:derby:// localhost:1527 / Libraryprj; create = true;
String createString =CREATE TABLE Employee(NAME VARCHAR(32)NOT NULL,ADDRESS VARCHAR(50)NOT NULL);
try {
Class.forName(driver);
} catch(java.lang.ClassNotFoundException e){
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(connectionURL);
语句stmt =(Statement)conn.createStatement();
stmt.executeUpdate(createString);
PreparedStatement psInsert = conn.prepareStatement(insert into Employee values(?,?));
psInsert.setString(1,args [0]); $ b $ p psInsert.setString(2,args [1]);
psInsert.executeUpdate();
语句stmt2 =(Statement)conn.createStatement();
ResultSet rs = stmt2.executeQuery(select * from Employee);
int num = 0;
while(rs.next()){
System.out.println(++ num +:Name:+ rs.getString(1)+\\\
Address+ rs.getString (2));
}
rs.close();
} catch(Exception e){
e.printStackTrace();
}
}
}
解决方案>
如果您使用Tomcat,请从下载derbyclient.jar。并将jar文件复制到Tomcat的lib文件夹。
I use Netbeans, doing a java app. I created a class ConnectDB for db connetion using Java DB in netbeans. i started the server and ten conneted to db. when i run the file it produce
java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver @ 25 line
and
java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/Libraryprj;create=true
@30 th line of code
the code is below
package Lms;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
/**
*
* @author JOJO
*/
public class ConnectDB {
static Connection conn;
public static void main(String[] args) {
String driver = "org.apache.derby.jdbc.ClientDriver";
String connectionURL = "jdbc:derby://localhost:1527/Libraryprj;create=true";
String createString = "CREATE TABLE Employee (NAME VARCHAR(32) NOT NULL, ADDRESS VARCHAR(50) NOT NULL)";
try {
Class.forName(driver);
} catch (java.lang.ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(connectionURL);
Statement stmt = (Statement) conn.createStatement();
stmt.executeUpdate(createString);
PreparedStatement psInsert = conn.prepareStatement("insert into Employee values (?,?)");
psInsert.setString(1, args[0]);
psInsert.setString(2, args[1]);
psInsert.executeUpdate();
Statement stmt2 = (Statement) conn.createStatement();
ResultSet rs = stmt2.executeQuery("select * from Employee");
int num = 0;
while (rs.next()) {
System.out.println(++num + ": Name: " + rs.getString(1) + "\n Address" + rs.getString(2));
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
解决方案
If you use Tomcat download derbyclient.jar from here . And copy the jar file to Tomcat's lib folder.
这篇关于java.lang.ClassNotFoundException Netbeans java derby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!