i have written a jdbc program and compiled it successfully
on running it i got a error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/util/Ut
ilDummyPrintWriter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at DBCreate.main(DBCreate.java:7)
the program code is as follows:
import java.sql.*;
import java.util.Properties;

public class Rows
{
public static void main(String args[]) throws SQLException
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Properties p = new Properties();
p.put("User","sa");
p.put("Password","dss");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:2433",p);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT empno,ename,sal FROM emp");
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
System.out.println("the table is :");
for(int i=0;i<=cols;i++)
{
System.out.println(rsmd.getColumnLabel(i) + "\t");
}
System.out.println("\n");
while(rs.next())
{
int empno=rs.getInt(1);
String ename = rs.getString(2);
float sal=rs.getFloat(3);
System.out.println(empno + "\t" + ename + "\t" + sal);
}

rs.close();
stmt.close();
con.close();
}
catch(SQLException s)
{
s.printStackTrace();
}
catch(ClassNotFoundException c)
{
c.printStackTrace();
}
}
}
where is the error :idea:

Dani AI

Generated

Good catch from — that error is a runtime class-loading failure, not a SQL or query problem. A Java NoClassDefFoundError means the JVM tried to load a class that existed at compile time but cannot be found at runtime (usually a missing JAR or transitive dependency). (docs.oracle.com)

Historically Microsoft’s older SQL Server JDBC package (the 2000-era driver) shipped as multiple JARs — the driver’s helper/util classes are in the “util” JAR, so if you only put one of the files on the runtime classpath the driver will start to load and then fail when it needs that helper class. Make sure the driver installation’s JARs (msbase.jar, msutil.jar, mssqlserver.jar) are all on your runtime CLASSPATH — or switch to a modern single‑JAR driver (sqljdbc/sqljdbc4 or the current mssql‑jdbc packages) and the matching driver JAR for your JRE. (docs.oracle.com)

Quick, practical steps to fix:

  • Put the full set of driver JARs into the process runtime classpath (or the app‑server’s lib folder). WebLogic/Tomcat/etc. require the JARs to be visible to the container at startup. (docs.oracle.com)
  • Verify the missing class exists in a JAR: for example run jar -tf yourdriver.jar | grep Util (or use jar -tf + findstr on Windows).
  • If possible, upgrade to the current Microsoft JDBC driver JAR that matches your Java version (one JAR to manage). (learn.microsoft.com)

Also note one bug in the posted code to fix after the driver issue: JDBC ResultSetMetaData uses 1‑based column indexes — iterate from 1 to getColumnCount() when printing column labels to avoid off‑by‑one errors. (download.java.net)

inside your JDBC driver.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.