这些功能在本地工作,但是一旦我为某些页面托管此消息显示
java.sql.SQLException: Access denied for user 'myshelf'@'54.235.58.92' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:894)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3808)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1256)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2032)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:729)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.GeneratedConstructorAccessor71.newInstance(Unknown Source
我正在尝试创建一个新目录并将封面图片添加到 S3 存储桶
字符串 awsAccessKey = ""; 字符串 awsSecretKey = "";
String name_val="";
String desc_val="";
// HttpSession session = request.getSession(true);
//String username = (String) session.getAttribute("user_session");
//String clubfield=(String) session.getAttribute("res_ses");*/
// int att_id=0;
//String[] ccode;
String fieldname ="",fieldvalue="",fieldname1="" ,fieldvalue2="",fieldname2="",fieldvalue1="" ,fieldvalue3="",fieldname3="";
String categori="" ;
String category="" ;
String catalog="" ;
String nb="" ;
// String cclub="";
Connection con = null;
// ccode = clubfield.split("-");
// cclub=ccode[0];
String filetit="";
String filename="";
String test="";
int s=0;
// System.out.println("club code"+cclub);
try{
AWSCredentials awsCredentials =
new AWSCredentials(awsAccessKey, awsSecretKey);
S3Service s3Service = new RestS3Service(awsCredentials);
S3Bucket[] myBuckets = s3Service.listAllBuckets();
System.out.println("How many buckets to I have in S3? " + myBuckets.length);
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : items) {
if (item.isFormField()) {
fieldname = item.getFieldName();
if(fieldname.equals("catalog")){
name_val=item.getString();
}
if(fieldname.equals("catalog")){
catalog=item.getString();
System.out.println(catalog);
}
if(fieldname.equals("desc")){
desc_val=item.getString();
}
if(fieldname.equals("cat")){
category=item.getString();
System.out.println(category);
}
if(fieldname.equals("nb")){
nb=item.getString();
System.out.println(nb);
}
fieldvalue = item.getString();
fieldname1 = item.getFieldName();
System.out.println("fieldname1"+fieldname1);
fieldvalue1 = item.getString();
fieldname2 = item.getFieldName();
fieldvalue2 = item.getString();
System.out.println("fieldname1"+ fieldvalue);
System.out.println("fieldname"+fieldname+ "--"+fieldvalue);
System.out.println(fieldname1+ "--"+fieldvalue1);
System.out.println(fieldname3+ "--"+fieldvalue3);
filetit=fieldvalue+"/"+filename;
} else {
// Process form file field (input type="file").
filename = FilenameUtils.getName(item.getName());
System.out.println("filename come on come on--"+filename);
if(!filename.equals(""))
{ InputStream filecontent = item.getInputStream();
// System.out.println(att_id+"/"+cclub+"_clubcode.jpg");
//filetit= request.getParameter("file");
System.out.println( filename );
S3Object s3obj = new S3Object("myshelf/brand/"+filename);
s3obj.setDataInputStream(filecontent);
s3Service.putObject("foofystestbucket", s3obj);
}
}
}
我认为我在这部分有问题,因为我使用不同的方式连接到数据库 public class Connect {
private java.sql.Connection conn=null;
public Connect () {}
public boolean dbConnect(){
boolean ok = false;
try {
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException ex){
ok = false;
}
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/myshelf?useServerPrepStmts=false", "myshelf", "myshelffoofysPASS");
// conn=DriverManager.getConnection("jdbc:mysql://174.129.206.66:3306/myshelf","myshelf","myshelffoofysPASS");
// conn=DriverManager.getConnection("jdbc:mysql://localhost/myshelf","root","");
ok = true;
}
catch (SQLException e) {
ok = false;
}
return ok;
}
public static Connection DbConn() throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
// return DriverManager.getConnection("jdbc:mysql://174.129.206.66/myshelf","myshelf","myshelffoofysAPI");
//return DriverManager.getConnection("jdbc:mysql://localhost/myshelf","root","");
return DriverManager.getConnection("jdbc:mysql://localhost:3306/myshelf?useServerPrepStmts=false", "myshelf", "myshelffoofysAPI");
}
public java.sql.Connection getConn() {
return conn;
}
}