哥哥姐姐们帮小弟看看这段程序问题在那里?
JSP连接SQL数据库的,我用的是JDBC-ODBC
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<%!
public String codeToString(String str)
{//处理中文字符串的函数
String s=str;
try
{
byte tempB[]=s.getBytes( "ISO-8859-1 ");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<%
for(int i=1;i <=4;i++){
//接收客户端提交的数据
String list_number=codeToString(request.getParameter( "list_number "));
String id=codeToString(request.getParameter( "id_ "+i+ " "));
if(id==null)//无内容则设为空串
id= " ";
String sort_number=codeToString(request.getParameter( "sort_number_ "+i+ " "));
if(sort_number==null)//无内容则设为空串
sort_number= " ";
String e_name=codeToString(request.getParameter( "e_name_ "+i+ " "));
if(e_name==null)//无内容则设为空串
e_name= " ";
String e_size=codeToString(request.getParameter( "e_size_ "+i+ " "));
if(e_size==null)//无内容则设为空串
e_size= " ";
String unit=codeToString(request.getParameter( "unit_ "+i+ " "));
if(unit==null)//无内容则设为空串
unit= " ";
String amount=codeToString(request.getParameter( "amount_ "+i+ " "));
if(amount==null)//无内容则设为空串
amount= " ";
String location=codeToString(request.getParameter( "location_ "+i+ " "));
if(location==null)//无内容则设为空串
location= " ";
String facturer=codeToString(request.getParameter( "facturer_ "+i+ " "));
if(facturer==null)//无内容则设为空串
facturer= " ";
String s_date=codeToString(request.getParameter( "data "));
if(s_date==null)//无内容则设为空串
s_date= " ";
out.print(s_date);
%>
<%//构造追加记录SQL语句
String sqlString=null;//SQL语句
sqlString= "insert into shouTable(list_number,id,sort_number,e_name,e_size,unit,amount,location,facturer,s_date) "+
" values( ' "+list_number+ " ', ' "+id+ " ', ' "+sort_number+ " ', ' "+e_name+ " ', ' "+e_size+ " ', ' "+unit+ " ', ' "+amount+ " ', ' "+location+ " ', ' "+facturer+ " ', ' "+s_date+ " ') ";
%>
<%//执行SQL语句
try
{ Connection con;
Statement sql;
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
con=DriverManager.getConnection( "jdbc:odbc;shangdian ");
sql=con.createStatement();
sql.executeUpdate(sqlString);
con.close();
}
catch(SQLException e1)
{
out.print( "SQL异常! ");
}
}
%>
程序提示错误为
“SQL异常!”
小弟新手,不知道错误在那里,请多指教!!
[解决办法]
你这种提示应该是数据库连接那里错误,我都是用JDBC连接的,ODBC没用过,你也可以用我这两句替换一下测试看看
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
con = DriverManager.getConnection( "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=shangdian ", "sa ", "sa ");
[解决办法]
不能把详细错误信息贴出来么?
[解决办法]
odbc没有用过,不过你的 "jdbc:odbc;shangdian "中的分隔符是个 "; "肯定是错的.换成 ": "试试.
[解决办法]
SQL异常,你是指插入语句出错?
如果是的话把sqlString 打在控制台打出来,然后在PL/SQL里面执行下,看看能不能插入
最好把错误信息贴出来清楚了