execute都通不过,还没到取数据的时候呢。
解决方案 »
- Swing开发问题:怎么在事件中实时动态刷新GUI?
- 一道有趣的线程问题!
- 我想在同一个java 文件中,把不同的类定义在不同的包中,要怎么做?
- 请高手指教Iterator接口的问题
- 一个小问题需要澄清
- 请问如何得到jdbTable中隐藏列中的值 ?
- 求助:请问在swing界面中怎样设置一个textfield的输入法的状态
- Toolkit.getDefaultToolkit().getScreenSize()获取的是全屏幕的大小,我想取去掉下面"开始"那一行的大小怎么取啊
- 请各位大虾都来看看,我还是一个初学者!!谢谢。
- String转换到int
- 如何向application的frame画线?解决就给分
- 一个小问题,这个变量是什么类型的???
statement.execute(sql); //这时发生上述的错误
换个微软自己出的SQL server 2k jdbc 2.0驱动程序
另外,用JDBC 2。0就没有解决办法了吗?我用的是微软出的SQL server 2k jdbc
/*
/*@ author:yjx
/*@ date:2001-7-9
*//*import package file*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.lang.*;public class Loginservlet extends HttpServlet
{
public void doPost(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,java.io.IOException
{
PrintWriter out;
String strUserName,strPWD;
String strDBDriver,strURL;
String strSQL,strTemp;
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
int iExist=0;//0:not exits,1:exits
HttpSession session; session=req.getSession();
out = resp.getWriter(); //get parameters
strUserName=req.getParameter("username");
strPWD=req.getParameter("password"); //set database connection parameter value
strDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
strURL="jdbc:odbc:wygl"; if(strUserName!=null || strUserName.compareTo("")!=0){
//instance session variable:
session.putValue("login_name","");
session.putValue("user_name","");
session.putValue("dept_id","");
session.putValue("duty","");
session.putValue("mright","");
session.putValue("uitype","");
session.putValue("logined","false");
session.putValue("info","null");
//connect database
try{
Class.forName(strDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("error:"+e.getMessage());
} try{
conn=DriverManager.getConnection(strURL);
stmt=conn.createStatement();
}catch(SQLException e){
System.out.println("error:"+e.getMessage());
}
strSQL="select * from sys_user where login_name='"+strUserName+"' and user_pwd='"+strPWD+"'"; try{
rs=stmt.executeQuery(strSQL);
if(rs.next()){
session.putValue("login_name",strUserName); session.putValue("logined","true"); strTemp=rs.getString("user_name");
session.putValue("user_name",strTemp); strTemp=rs.getString("dept_id");
session.putValue("dept_id",strTemp);
strTemp=rs.getString("duty");
session.putValue("duty",strTemp); strTemp=rs.getString("mright");
session.putValue("mright",strTemp); strTemp=rs.getString("uitype");
session.putValue("uitype",strTemp); resp.sendRedirect("/wygl/jsp/sysindex.jsp");
}else{
resp.sendRedirect("/wygl/jsp/errorindex.jsp");
}
}catch(SQLException e){
System.err.println("error:"+e.getMessage());
}
}
}
}
我建立了db1数据原,在这个数据原下面,有个数据库test 他下面有个city表我现在想访问他
对了用户名是sa 密码是password
jdk1.3下面不是有一个jdbc-odbc驱动程序马,我用这个来访问sqlserver数据库
String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
String dbURL = "jdbc:odbc:test";
Properties prop = new Properties();
prop.put("user","sa");
prop.put("password","password");
try {
driver = (Driver) Class.forName(driverName).newInstance();
connection = driver.connect(dbURL,prop);
} catch (SQLException sqle) {
System.out.println(sqle);
}