一个 SQL 异常被捕获说“java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified”。我在 Swings 中使用了相同的连接代码,其中代码执行完美,包括 SQL 语句执行。如果可以对代码进行任何更改,请帮助我。
import javax.servlet.*;
import java.io.*;
import java.sql.*;
import javax.servlet.http.*;
public class forwardeg23 extends HttpServlet
{
Statement st;
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException
{
PrintWriter out = res.getWriter();
out.println("this is from forwardeg23");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:mysqllatest","root","tiger");
out.println("Atleast Connection Established");
st = con.createStatement();
}
catch(Exception ef){out.println(ef+"\n Error in creating connection");}
try{
st.executeUpdate("INSERT INTO student(Name,Marks) VALUES ('ABC',85)");
}
catch(Exception af){out.println("Exception HERE");}
}
}