谁能帮帮我(关于jdbc的问题) execute都通不过,还没到取数据的时候呢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可能是由于jdbc不能识别该类型,换个sql的驱动程序看看 String sql = "select name,population from cities"; //population 是bigint类型的字段statement.execute(sql); //这时发生上述的错误 我觉得是驱动程序的问题,程序找不到你的驱动程序。因为我上次用postgresql,也是出现这种问题(驱动程序还要支持java),不过,我用的是jbuilder5,在project properties,里加上驱动程序包就ok。 换个微软自己出的SQL server 2k jdbc 2.0驱动程序 JDBC 3。0版本提供对BIG 类型的支持,2。0版本的可能不行 JDBC 3。0现在有没有正式版的?另外,用JDBC 2。0就没有解决办法了吗?我用的是微软出的SQL server 2k jdbc 一很用以String读出来,后面再作处理,在JAVA再作处理很容易/*/*@ 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()); } } }} 关于nicolas的回答,我在前面已经提到,我这个包含对bigint字段的表的查询在execute时就已经出错,所以转换到任何类型都是无法实现的 给 mellono 你好,你用的是jdk自己带的jdbc-odbc吗,我现在不知道怎么样来连接数据库你能够和我说说吗??我建立了db1数据原,在这个数据原下面,有个数据库test 他下面有个city表我现在想访问他对了用户名是sa 密码是passwordjdk1.3下面不是有一个jdbc-odbc驱动程序马,我用这个来访问sqlserver数据库 回复boyandgirl你好,我用的数据库驱动是微软的jdbc for SQL Server 2000。用jdbc-odbc也可以,只不过限制多多。用jdbc-odbc连接数据库的程序示例写在下面: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);} 做联通短信接口(JAVA)的开发遇到个问题? 给toolbar加快捷键后,当toolbar隐藏,快捷键无响应 这几天她不理我了,怎么办? 一个问题困扰我很久了,请各位大哥帮忙 J2SE1.4中针对ZIP开发的问题 第一次用JBuilder,请帮忙一下!谢谢! ★★★祝愿大家新年快乐,心想事成。散分★★★ 如何将java编译成.exe可执行文件! 本人刚学java,有一个问题请教大家: 超级简单快来捡分 如何向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);
}