以下のプログラムを実行すると、エラーが発生し、これに対する解決策がわかります。メソッドInsTableのパラメーターを使用してデータベースにデータを渡す必要があります。
import java.io.*;
import java.sql.*;
import java.util.*;
public class InsertusrProf
{
public static Connection prepareConnection()throws ClassNotFoundException,SQLException
{
String dcn="oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin:@JamesPJ-PC:1521:skypark";
String usname="system";
String pass="tiger";
Class.forName(dcn);
return DriverManager.getConnection(url,usname,pass);
}
public static void InsTable(String uname,String photo1,String video1,String music1,String notes1,String messages1,String link,String frd,String cmt,String lik,String ulik,String shrs,String qst,String answ,String updt,String thms,String wrd,String comm,String grp,String pgs,String ntfcn,String rqst,String tps,String tg)throws ClassNotFoundException,SQLException,FileNotFoundException
{
StringBuilder sb=new StringBuilder(1024);;
sb.append("insert into ").append(uname).append("(PHOTO,VIDEO,MUSIC,NOTES,MESSAGES,LINKS,FRIENDS,COMMENTS,LIKES,UNLIKES,SHARES,QSTNS,ANS,UPDATES,THEMS,WORDS,LANGUAGES,RELEGION,PRIVACY,HOBBIES,FAV,QULIFICATION,COMMUNITIES,GRPS,PAGES,NOTIFICATION,REQUESTS,TIPS,CITY,TAG)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
String stmnt=sb.toString();
Connection con=prepareConnection();
PreparedStatement ps=con.prepareStatement(stmnt);
ps.setString(1,uname);
File fl=new File(photo1);
FileInputStream fis=new FileInputStream(fl);
ps.setBinaryStream(2,fis,(int)fl.length());
File fl1=new File(music1);
FileInputStream fis1=new FileInputStream(fl1);
ps.setBinaryStream(3,fis1,(int)fl1.length());
File fl2=new File(video1);
FileInputStream fis2=new FileInputStream(fl2);
ps.setBinaryStream(4,fis2,(int)fl2.length());
File fl3=new File(shrs);
FileInputStream fis3=new FileInputStream(fl3);
ps.setBinaryStream(12,fis3,(int)fl3.length());
File fl4=new File(updt);
FileInputStream fis4=new FileInputStream(fl4);
ps.setBinaryStream(15,fis4,(int)fl4.length());
File fl5=new File(notes1);
FileReader fr=new FileReader(fl5);
//BufferedReader r=new BufferedReader(notes1.getCharacterStream());
ps.setCharacterStream(5,fr,(int)fl5.length());
File fl6=new File(messages1);
FileReader fr1=new FileReader(fl6);
ps.setCharacterStream(6,fr1,(int)fl6.length());
ps.setString(7,link);
ps.setString(8,frd);
File fl7=new File(cmt);
FileReader fr2=new FileReader(fl7);
ps.setCharacterStream(9,fr2,(int)fl7.length());
ps.setString(10,lik);
ps.setString(11,ulik);
File fl8=new File(qst);
FileReader fr3=new FileReader(fl8);
ps.setCharacterStream(13,fr3,(int)fl8.length());
File fl9=new File(answ);
FileReader fr4=new FileReader(fl9);
ps.setCharacterStream(14,fr4,(int)fl9.length());
ps.setString(16,thms);
File fl0=new File(wrd);
FileReader fr5=new FileReader(fl0);
ps.setCharacterStream(17,fr5,(int)fl0.length());
ps.setString(18,comm);
ps.setString(19,grp);
ps.setString(20,pgs);
File fls=new File(ntfcn);
FileReader fr6=new FileReader(fls);
ps.setCharacterStream(21,fr6,(int)fls.length());
ps.setString(22,rqst);
File fls1=new File(tps);
FileReader fr7=new FileReader(fls1);
//BufferedReader r=new BufferedReader(tps.getCharacterStream());
ps.setCharacterStream(23,fr7,(int)fls1.length());
ps.setString(24,tg);
int i=ps.executeUpdate();
System.out.println("<<<<<<<Record Inserted Successfully>>>>>>> Count :"+i);
con.close();
}
public static void main(String args[])throws Exception
{
String uname="james";
String photo1="C:/Users/James P J/Documents/javaprog/img1.jpg";
String video1="C:/Users/James P J/Documents/javaprog/How To Make 3D Text In Photoshop (ADOBE PHOTOSHOP CS6 TUTORIAL).flv";
String music1="C:/Users/James P J/Documents/javaprog/Lelepadi.mp3";
String notes1="C:/Users/James P J/Documents/javaprog/test.java";
String messages1="C:/Users/James P J/Documents/javaprog/test.java";
String link="aaaaa";
String frd="bbbb";
String cmt="C:/Users/James P J/Documents/javaprog/test.java";
String lik="asadssfds";
String ulik="zxzxxzcx";
String shrs="C:/Users/James P J/Documents/javaprog/img1.jpg";
String qst="C:/Users/James P J/Documents/javaprog/test.java";
String answ="C:/Users/James P J/Documents/javaprog/test.java";
String updt="C:/Users/James P J/Documents/javaprog/img1.jpg";
String thms="bgfvdft";
String wrd="C:/Users/James P J/Documents/javaprog/test.java";
String langs="erdgdfgf";
String rlgn="bngfhgfh";
String prvc="zxcsdw";
String hbs="bgnbvc";
String fvt="tgfhfghjfgh";
String qlf="mklkopi";
String comm="mbnfchgeshgw";
String grp="bgyeadb";
String pgs="hfhfj";
String ntfcn="C:/Users/James P J/Documents/javaprog/test.java";
String rqst="ghfhgfh";
String tps="C:/Users/James P J/Documents/javaprog/test.java";
String cty="jjkhgjghjk";
String tg="qwewr";
InsTable(uname,photo1,video1,music1,notes1,messages1,link,frd,cmt,lik,ulik,shrs,qst,answ,updt,thms,wrd,comm,grp,pgs,ntfcn,rqst,tps,tg);
}
}
私が作成した手順でモードをINOUTにすることでこのエラーを解決しようとしましたが、次のエラーは解決されませんでした。解決策が見つかった場合は、答えてください。エラーは:
Exception in thread "main" java.sql.SQLException: Missing IN or OUT parameter at
index:: 25
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:146)
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(Or
aclePreparedStatement.java:1681)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePrep
aredStatement.java:3280)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePrepar
edStatement.java:3368)
at skypark.InsertusrProf.InsTable(InsertusrProf.java:99)
at skypark.InsertusrProf.main(InsertusrProf.java:138)
Press any key to continue . . .
解決策を知っているなら、これに答えてください....よろしくお願いします...